Skip to content

Commit

Permalink
Auto merge of #28 - troy/try-merged, r=TroyKomodo
Browse files Browse the repository at this point in the history
Troy/try merged
Fixes an unsound bug related to running a dry-run on an already merged PR.

Adds a mechanism for auto-syncing labels.

Removes the restriction on running tests on PRs

Requested-by: TroyKomodo <[email protected]>
  • Loading branch information
scuffle-brawl[bot] authored Jan 3, 2025
2 parents 5e01743 + 48fd29d commit 654c37a
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/labels.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
test:
name: Test
runs-on: ubuntu-24.04
if: ${{ !cancelled() && github.event_name != 'pull_request' }}
services:
postgres:
image: postgres
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/sync-labels.yaml
Original file line number Diff line number Diff line change
@@ -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
84 changes: 84 additions & 0 deletions server/src/command/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ async fn handle_with_pr<R: GitHubRepoClient>(
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
Expand Down Expand Up @@ -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
<details>
<summary>Error</summary>
Currently running runs on a PR that has been merged is not supported
</details>
");
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());
}
}

0 comments on commit 654c37a

Please sign in to comment.