6
6
using System . Linq ;
7
7
using System . Net ;
8
8
using System . Net . Http ;
9
- using System . Net . Http . Json ;
10
9
using System . Security . Cryptography ;
11
- using System . Text . Json . Serialization ;
12
10
using System . Text . RegularExpressions ;
13
11
using System . Threading ;
14
12
using System . Threading . Tasks ;
@@ -406,12 +404,6 @@ private async Task GetNeeds(BuildTask task, DirectoryInfo needsDir, HashSet<Buil
406
404
407
405
}
408
406
409
- private class HasteResponse
410
- {
411
- [ JsonPropertyName ( "key" ) ]
412
- public string ? Key { get ; set ; }
413
- } ;
414
-
415
407
/// <summary>
416
408
/// A set of diffs.
417
409
/// </summary>
@@ -424,7 +416,7 @@ public record PluginDiffSet(string? HosterUrl, string? RegularDiffLink, string?
424
416
425
417
private async Task < PluginDiffSet > GetPluginDiff ( DirectoryInfo workDir , BuildTask task , IEnumerable < BuildTask > tasks , bool doSemantic )
426
418
{
427
- async Task UploadDiffToS3 ( string output , string type , string extension , string contentType )
419
+ async Task < string > UploadDiffToS3 ( string output , string type , string extension , string contentType )
428
420
{
429
421
if ( this . setup . InternalS3Client == null )
430
422
throw new Exception ( "S3 client not set up" ) ;
@@ -448,6 +440,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
448
440
var res = await this . setup . InternalS3Client . PutObjectAsync ( request ) ;
449
441
if ( res is not { HttpStatusCode : HttpStatusCode . OK } )
450
442
throw new Exception ( $ "Failed to upload diff to S3: { res ? . HttpStatusCode } ") ;
443
+
444
+ return $ "https://{ this . setup . DiffsBucketName } .{ this . setup . InternalS3WebUrl } /{ key } ";
451
445
}
452
446
453
447
var internalName = task . InternalName ;
@@ -468,9 +462,7 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
468
462
Log . Information ( "Overriding diff haveCommit with {Commit} from {Channel}" , haveCommit , removeTask . Channel ) ;
469
463
}
470
464
}
471
-
472
- using var client = new HttpClient ( ) ;
473
-
465
+
474
466
var url = host . AbsoluteUri . Replace ( ".git" , string . Empty ) ;
475
467
476
468
string ? hosterUrl = null ;
@@ -512,21 +504,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
512
504
513
505
if ( haveCommit == emptyTree )
514
506
return null ;
515
-
516
- var res = await client . PostAsync ( "https://haste.soulja-boy-told.me/documents" , new StringContent ( diffOutput ) ) ;
517
- res . EnsureSuccessStatusCode ( ) ;
518
-
519
- try
520
- {
521
- await UploadDiffToS3 ( diffOutput , "plain" , ".diff" , "text/plain" ) ;
522
- }
523
- catch ( Exception ex )
524
- {
525
- Log . Error ( ex , "Failed to upload diff to S3" ) ;
526
- }
527
507
528
- var json = await res . Content . ReadFromJsonAsync < HasteResponse > ( ) ;
529
- return $ "https://haste.soulja-boy-told.me/{ json ! . Key } .diff";
508
+ return await UploadDiffToS3 ( diffOutput , "plain" , "diff" , "text/plain" ) ;
530
509
}
531
510
532
511
async Task < string ? > MakeAndUploadSemantic ( )
@@ -555,21 +534,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
555
534
556
535
if ( haveCommit == emptyTree )
557
536
return null ;
558
-
559
- var res = await client . PostAsync ( "https://haste.soulja-boy-told.me/documents" , new StringContent ( diffOutput ) ) ;
560
- res . EnsureSuccessStatusCode ( ) ;
561
537
562
- try
563
- {
564
- await UploadDiffToS3 ( diffOutput , "semantic" , ".html" , "text/html" ) ;
565
- }
566
- catch ( Exception ex )
567
- {
568
- Log . Error ( ex , "Failed to upload semantic diff to S3" ) ;
569
- }
570
-
571
- var json = await res . Content . ReadFromJsonAsync < HasteResponse > ( ) ;
572
- return $ "https://haste.soulja-boy-told.me/raw/{ json ! . Key } .html";
538
+ return await UploadDiffToS3 ( diffOutput , "semantic" , "html" , "text/html" ) ;
573
539
}
574
540
575
541
var linesAdded = 0 ;
@@ -600,12 +566,12 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
600
566
601
567
if ( match . Success )
602
568
{
603
- if ( ! match . Groups . TryGetValue ( "numInsertions" , out var groupInsertions ) || ! int . TryParse ( groupInsertions ? . Value , out linesAdded ) )
569
+ if ( ! match . Groups . TryGetValue ( "numInsertions" , out var groupInsertions ) || ! int . TryParse ( groupInsertions . Value , out linesAdded ) )
604
570
{
605
571
Log . Error ( "Could not parse insertions" ) ;
606
572
}
607
573
608
- if ( ! match . Groups . TryGetValue ( "numDeletions" , out var groupDeletions ) || ! int . TryParse ( groupDeletions ? . Value , out linesRemoved ) )
574
+ if ( ! match . Groups . TryGetValue ( "numDeletions" , out var groupDeletions ) || ! int . TryParse ( groupDeletions . Value , out linesRemoved ) )
609
575
{
610
576
Log . Error ( "Could not parse deletions" ) ;
611
577
}
0 commit comments