Skip to content

Commit 85f949b

Browse files
committed
stop uploading diffs to haste
1 parent 28c3ff8 commit 85f949b

File tree

1 file changed

+8
-42
lines changed

1 file changed

+8
-42
lines changed

Plogon/BuildProcessor.cs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
using System.Linq;
77
using System.Net;
88
using System.Net.Http;
9-
using System.Net.Http.Json;
109
using System.Security.Cryptography;
11-
using System.Text.Json.Serialization;
1210
using System.Text.RegularExpressions;
1311
using System.Threading;
1412
using System.Threading.Tasks;
@@ -406,12 +404,6 @@ private async Task GetNeeds(BuildTask task, DirectoryInfo needsDir, HashSet<Buil
406404

407405
}
408406

409-
private class HasteResponse
410-
{
411-
[JsonPropertyName("key")]
412-
public string? Key { get; set; }
413-
};
414-
415407
/// <summary>
416408
/// A set of diffs.
417409
/// </summary>
@@ -424,7 +416,7 @@ public record PluginDiffSet(string? HosterUrl, string? RegularDiffLink, string?
424416

425417
private async Task<PluginDiffSet> GetPluginDiff(DirectoryInfo workDir, BuildTask task, IEnumerable<BuildTask> tasks, bool doSemantic)
426418
{
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)
428420
{
429421
if (this.setup.InternalS3Client == null)
430422
throw new Exception("S3 client not set up");
@@ -448,6 +440,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
448440
var res = await this.setup.InternalS3Client.PutObjectAsync(request);
449441
if (res is not { HttpStatusCode: HttpStatusCode.OK })
450442
throw new Exception($"Failed to upload diff to S3: {res?.HttpStatusCode}");
443+
444+
return $"https://{this.setup.DiffsBucketName}.{this.setup.InternalS3WebUrl}/{key}";
451445
}
452446

453447
var internalName = task.InternalName;
@@ -468,9 +462,7 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
468462
Log.Information("Overriding diff haveCommit with {Commit} from {Channel}", haveCommit, removeTask.Channel);
469463
}
470464
}
471-
472-
using var client = new HttpClient();
473-
465+
474466
var url = host.AbsoluteUri.Replace(".git", string.Empty);
475467

476468
string? hosterUrl = null;
@@ -512,21 +504,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
512504

513505
if (haveCommit == emptyTree)
514506
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-
}
527507

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");
530509
}
531510

532511
async Task<string?> MakeAndUploadSemantic()
@@ -555,21 +534,8 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
555534

556535
if (haveCommit == emptyTree)
557536
return null;
558-
559-
var res = await client.PostAsync("https://haste.soulja-boy-told.me/documents", new StringContent(diffOutput));
560-
res.EnsureSuccessStatusCode();
561537

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");
573539
}
574540

575541
var linesAdded = 0;
@@ -600,12 +566,12 @@ async Task UploadDiffToS3(string output, string type, string extension, string c
600566

601567
if (match.Success)
602568
{
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))
604570
{
605571
Log.Error("Could not parse insertions");
606572
}
607573

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))
609575
{
610576
Log.Error("Could not parse deletions");
611577
}

0 commit comments

Comments
 (0)