Skip to content

Commit

Permalink
Auto merge of #18 - troy/pr-labels, r=TroyKomodo
Browse files Browse the repository at this point in the history
implement the pr label feature
this commit lays the ground work for adding labels to PRs depending on the CI Run Status.

The config type was already implemented but the actual labeling action was not.

Requested-by: TroyKomodo <[email protected]>
  • Loading branch information
scuffle-brawl[bot] authored Dec 26, 2024
2 parents dd3beaa + 7261020 commit 94a3be7
Show file tree
Hide file tree
Showing 21 changed files with 966 additions and 90 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,21 @@ jobs:
- name: Run tests
run: cargo +nightly llvm-cov nextest --no-fail-fast --all-features --lcov --output-path ./lcov.info --profile ci

- name: PR Override
- name: Codecov Override
if: ${{ startsWith(github.ref, 'refs/heads/automation/brawl/try/') }}
run: |
PR_NUMBER=$(echo ${{ github.ref }} | sed -n 's/^refs\/heads\/automation\/brawl\/try\/\([0-9]*\)$/\1/p')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
RUN_COMMIT_SHA=$(git log -1 --pretty=format:%H)
echo "RUN_COMMIT_SHA=$RUN_COMMIT_SHA" >> $GITHUB_ENV
- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
files: ./lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
override_pr: ${{ env.PR_NUMBER || github.event.pull_request.number || '' }}
override_commit: ${{ env.RUN_COMMIT_SHA || github.sha }}
verbose: true

- name: Upload test results to Codecov
Expand All @@ -174,6 +177,7 @@ jobs:
with:
files: ./target/nextest/ci/junit.xml
override_pr: ${{ env.PR_NUMBER || github.event.pull_request.number || '' }}
override_commit: ${{ env.RUN_COMMIT_SHA || github.sha }}
token: ${{ secrets.CODECOV_TOKEN }}

brawl-done:
Expand Down
1 change: 1 addition & 0 deletions migrations/2024-12-25-001112_label_state/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE github_pr DROP COLUMN added_labels;
1 change: 1 addition & 0 deletions migrations/2024-12-25-001112_label_state/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE github_pr ADD COLUMN added_labels TEXT[] NOT NULL DEFAULT '{}' CHECK (array_position(added_labels, NULL) IS NULL);
26 changes: 23 additions & 3 deletions migrations/schema.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- migrations/schema.unpatched.rs 2024-12-21 01:00:50.435153015 +0000
+++ server/src/database/schema.rs 2024-12-21 00:55:41.850491800 +0000
--- migrations/schema.unpatched.rs 2024-12-25 03:01:31.500330121 +0000
+++ server/src/database/schema.rs 2024-12-25 03:01:20.600359108 +0000
@@ -1,38 +1,44 @@
+#![cfg_attr(coverage_nightly, coverage(off))]
// @generated automatically by Diesel CLI.
Expand Down Expand Up @@ -85,7 +85,27 @@
///
/// (Automatically generated by Diesel.)
status -> GithubPrStatus,
@@ -320,12 +326,13 @@
@@ -297,16 +303,16 @@
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
default_priority -> Nullable<Int4>,
/// The `added_labels` column of the `github_pr` table.
///
- /// Its SQL type is `Array<Nullable<Text>>`.
+ /// Its SQL type is `Array<Text>`.
///
- /// (Automatically generated by Diesel.)
- added_labels -> Array<Nullable<Text>>,
+ /// (Manually changed from `Array<Nullable<Text>>` to `Array<Text>`)
+ added_labels -> Array<Text>,
}
}

diesel::table! {
/// Representation of the `health_check` table.
///
@@ -326,12 +332,13 @@
updated_at -> Timestamptz,
}
}
Expand Down
6 changes: 6 additions & 0 deletions migrations/schema.unpatched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ diesel::table! {
///
/// (Automatically generated by Diesel.)
default_priority -> Nullable<Int4>,
/// The `added_labels` column of the `github_pr` table.
///
/// Its SQL type is `Array<Nullable<Text>>`.
///
/// (Automatically generated by Diesel.)
added_labels -> Array<Nullable<Text>>,
}
}

Expand Down
17 changes: 9 additions & 8 deletions server/src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![cfg_attr(all(coverage_nightly, test), coverage(off))]

use std::net::SocketAddr;
Expand Down Expand Up @@ -162,14 +163,14 @@ impl scuffle_bootstrap_telemetry::TelemetryConfig for Global {
}

impl scuffle_brawl::webhook::WebhookConfig for Global {
fn bind_address(&self) -> Option<SocketAddr> {
Some(self.config.github.webhook_bind)
}

fn webhook_secret(&self) -> &str {
&self.config.github.webhook_secret
}

fn bind_address(&self) -> Option<SocketAddr> {
Some(self.config.github.webhook_bind)
}

fn get_repo(
&self,
installation_id: InstallationId,
Expand All @@ -196,13 +197,13 @@ impl scuffle_brawl::webhook::WebhookConfig for Global {
Ok(())
}

fn delete_installation(&self, installation_id: InstallationId) -> anyhow::Result<()> {
self.github_service.delete_installation(installation_id);
async fn update_installation(&self, installation: Installation) -> anyhow::Result<()> {
self.github_service.update_installation(installation).await?;
Ok(())
}

async fn update_installation(&self, installation: Installation) -> anyhow::Result<()> {
self.github_service.update_installation(installation).await?;
fn delete_installation(&self, installation_id: InstallationId) -> anyhow::Result<()> {
self.github_service.delete_installation(installation_id);
Ok(())
}

Expand Down
7 changes: 4 additions & 3 deletions server/src/command/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
pr: PullRequest,
context: BrawlCommandContext<'_, R>,
) -> anyhow::Result<()> {
Pr::new(&pr, context.user.id, context.repo.id())
let db_pr = Pr::new(&pr, context.user.id, context.repo.id())
.upsert()
.get_result(conn)
.await
Expand All @@ -49,7 +49,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
context
.repo
.merge_workflow()
.cancel(&run, context.repo, conn)
.cancel(&run, context.repo, conn, &db_pr)
.await
.context("cancel ci run")?;

Expand Down Expand Up @@ -89,8 +89,9 @@ pub mod tests {
run: &CiRun<'_>,
repo: &impl GitHubRepoClient,
conn: &mut AsyncPgConnection,
pr: &Pr<'_>,
) -> anyhow::Result<()> {
let _ = (run, repo, conn);
let _ = (run, repo, conn, pr);
if self
.cancelled
.compare_exchange(
Expand Down
15 changes: 8 additions & 7 deletions server/src/command/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ async fn handle_with_pr<R: GitHubRepoClient>(

let branch = context.repo.config().try_branch(pr.number);

let db_pr = Pr::new(&pr, context.user.id, context.repo.id())
.upsert()
.get_result(conn)
.await
.context("update pr")?;

if let Some(run) = CiRun::active(context.repo.id(), pr.number)
.get_result(conn)
.await
Expand All @@ -90,7 +96,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
context
.repo
.merge_workflow()
.cancel(&run, context.repo, conn)
.cancel(&run, context.repo, conn, &db_pr)
.await
.context("cancel ci run")?;
} else {
Expand All @@ -115,12 +121,6 @@ async fn handle_with_pr<R: GitHubRepoClient>(
}
}

let db_pr = Pr::new(&pr, context.user.id, context.repo.id())
.upsert()
.get_result(conn)
.await
.context("update pr")?;

let run = CiRun::insert(context.repo.id(), pr.number)
.base_ref(base)
.head_commit_sha(command.head_sha.as_deref().unwrap_or_else(|| pr.head.sha.as_ref()).into())
Expand Down Expand Up @@ -199,6 +199,7 @@ mod tests {
run: &CiRun<'_>,
_: &impl GitHubRepoClient,
conn: &mut AsyncPgConnection,
_: &Pr<'_>,
) -> anyhow::Result<()> {
if self
.cancelled
Expand Down
10 changes: 8 additions & 2 deletions server/src/command/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
.get_result(conn)
.await?;

context.repo.merge_workflow().queued(&run, context.repo).await?;
context.repo.merge_workflow().queued(&run, context.repo, conn, &db_pr).await?;

Ok(())
}
Expand All @@ -131,7 +131,13 @@ mod tests {
}

impl GitHubMergeWorkflow for MockMergeWorkFlow {
async fn queued(&self, _: &CiRun<'_>, _: &impl GitHubRepoClient) -> anyhow::Result<()> {
async fn queued(
&self,
_: &CiRun<'_>,
_: &impl GitHubRepoClient,
_: &mut AsyncPgConnection,
_: &Pr<'_>,
) -> anyhow::Result<()> {
self.queued
.compare_exchange(
false,
Expand Down
10 changes: 8 additions & 2 deletions server/src/command/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
if run.is_dry_run {
context.repo.merge_workflow().start(&run, context.repo, conn, &db_pr).await?;
} else {
context.repo.merge_workflow().queued(&run, context.repo).await?;
context.repo.merge_workflow().queued(&run, context.repo, conn, &db_pr).await?;
}

Ok(())
Expand Down Expand Up @@ -132,7 +132,13 @@ mod tests {
Ok(true)
}

async fn queued(&self, _: &CiRun<'_>, _: &impl GitHubRepoClient) -> anyhow::Result<()> {
async fn queued(
&self,
_: &CiRun<'_>,
_: &impl GitHubRepoClient,
_: &mut AsyncPgConnection,
_: &Pr<'_>,
) -> anyhow::Result<()> {
self.queued
.compare_exchange(
false,
Expand Down
Loading

0 comments on commit 94a3be7

Please sign in to comment.