diff --git a/.github/labels.yaml b/.github/labels.yaml new file mode 100644 index 0000000..48060af --- /dev/null +++ b/.github/labels.yaml @@ -0,0 +1,30 @@ +- name: "B-brawl-failed" + color: "B60205" +- name: "B-brawl-merged" + color: "5319E7" +- name: "B-brawl-merging" + color: "006B75" +- name: "B-brawl-queued" + color: "C2E0C6" +- name: "B-brawl-try" + color: "FBCA04" +- name: "B-brawl-try-failed" + color: "B60205" +- name: "bug" + color: "d73a4a" +- name: "documentation" + color: "0075ca" +- name: "duplicate" + color: "cfd3d7" +- name: "enhancement" + color: "a2eeef" +- name: "good first issue" + color: "7057ff" +- name: "help wanted" + color: "008672" +- name: "invalid" + color: "e4e669" +- name: "question" + color: "d876e3" +- name: "wontfix" + color: "ffffff" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f19fce8..429b8fb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -113,7 +113,6 @@ jobs: test: name: Test runs-on: ubuntu-24.04 - if: ${{ !cancelled() && github.event_name != 'pull_request' }} services: postgres: image: postgres diff --git a/.github/workflows/sync-labels.yaml b/.github/workflows/sync-labels.yaml new file mode 100644 index 0000000..8e39442 --- /dev/null +++ b/.github/workflows/sync-labels.yaml @@ -0,0 +1,32 @@ +name: Sync Labels + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + push: + branches: + - main + paths: + - ".github/labels.yaml" + pull_request: + branches: + - main + +jobs: + synclabels: + name: Sync Labels + runs-on: ubuntu-24.04 + + permissions: write-all + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Sync labels + uses: crazy-max/ghaction-github-labeler@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + dry-run: ${{ github.event_name == 'pull_request' }} + yaml-file: .github/labels.yaml diff --git a/server/src/command/dry_run.rs b/server/src/command/dry_run.rs index d97130c..703ba48 100644 --- a/server/src/command/dry_run.rs +++ b/server/src/command/dry_run.rs @@ -42,6 +42,20 @@ async fn handle_with_pr( return Ok(()); } + if pr.merged_at.is_some() { + context + .repo + .send_message( + pr.number, + &messages::error( + "PR is already merged", + "Currently running runs on a PR that has been merged is not supported", + ), + ) + .await?; + return Ok(()); + } + if let Some(base_sha) = &mut command.base_sha { let Some(base_commit) = context.repo.get_commit(base_sha).await.context("get base commit")? else { context @@ -897,4 +911,74 @@ mod tests { assert!(run.is_none()); } + + #[tokio::test] + async fn test_dry_run_pr_merged() { + let mut conn = crate::database::get_test_connection().await; + + let (client, mut rx) = MockRepoClient::new(MockMergeWorkflow::default()); + + let pr = PullRequest { + number: 1, + merged_at: Some(Utc::now().into()), + ..Default::default() + }; + + let task = tokio::spawn(async move { + handle_with_pr( + &mut conn, + pr, + BrawlCommandContext { + repo: &client, + pr_number: 1, + user: User { + id: UserId(3), + login: "test".to_string(), + }, + }, + DryRunCommand { + head_sha: None, + base_sha: None, + }, + ) + .await + .unwrap(); + + (conn, client) + }); + + match rx.recv().await.unwrap() { + MockRepoAction::HasPermission { result, .. } => { + result.send(Ok(true)).unwrap(); + } + _ => panic!("unexpected action"), + } + + match rx.recv().await.unwrap() { + MockRepoAction::SendMessage { + issue_number, + message, + result, + } => { + assert_eq!(issue_number, 1); + insta::assert_snapshot!(message, @r" + 🚨 PR is already merged +
+ Error + + Currently running runs on a PR that has been merged is not supported + +
+ "); + result.send(Ok(())).unwrap(); + } + _ => panic!("unexpected action"), + } + + let (mut conn, client) = task.await.unwrap(); + + let run = CiRun::active(client.id(), 1).get_result(&mut conn).await.optional().unwrap(); + + assert!(run.is_none()); + } }