OPC # 0009: Gitea and OPC Build Webhooks
This commit is contained in:
@@ -251,6 +251,40 @@ public class GiteaService
|
||||
return await res.Content.ReadFromJsonAsync<GiteaWebhook>(JsonOpts, ct);
|
||||
}
|
||||
|
||||
// ── Commit Status ─────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Posts a commit status to Gitea (the CI "check" shown on a commit / PR).
|
||||
/// State values: "pending" | "success" | "failure" | "error".
|
||||
/// Context identifies which check — use "controlplane/build" for the build gate.
|
||||
/// </summary>
|
||||
public async Task PostCommitStatusAsync(
|
||||
string repoKey, string sha, string state, string description,
|
||||
string context = "controlplane/build", CancellationToken ct = default)
|
||||
{
|
||||
var (owner, repo) = ResolveOwnerRepo(repoKey);
|
||||
var body = JsonSerializer.Serialize(new
|
||||
{
|
||||
state,
|
||||
description,
|
||||
context,
|
||||
}, JsonOpts);
|
||||
|
||||
try
|
||||
{
|
||||
var res = await _http.PostAsync(
|
||||
$"repos/{owner}/{repo}/statuses/{sha}",
|
||||
new StringContent(body, Encoding.UTF8, "application/json"), ct);
|
||||
|
||||
if (!res.IsSuccessStatusCode)
|
||||
{
|
||||
var err = await res.Content.ReadAsStringAsync(ct);
|
||||
_log.LogWarning("Gitea PostCommitStatus {State} failed for {Sha}: {Err}", state, sha[..8], err);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { _log.LogWarning(ex, "Gitea PostCommitStatus threw"); }
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static string SlugifyTitle(string title) =>
|
||||
|
||||
Reference in New Issue
Block a user