Skip to content

Commit

Permalink
fix: only add labels to default branch (#100)
Browse files Browse the repository at this point in the history
* fix: only add labels to default branch

* test: fix fixtures
  • Loading branch information
codebytere committed Mar 17, 2022
1 parent d198d1e commit f3a252d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion spec/fixtures/add-triage-labels/build_pr_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"updated_at": "2020-12-08T01:24:55Z",
"closed_at": null,
"merged_at": null,
"labels": []
"labels": [],
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
}
},
"repository": {
"id": 9384267,
Expand Down
8 changes: 7 additions & 1 deletion spec/fixtures/add-triage-labels/ci_pr_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"updated_at": "2020-12-08T01:24:55Z",
"closed_at": null,
"merged_at": null,
"labels": []
"labels": [],
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
}
},
"repository": {
"id": 9384267,
Expand Down
8 changes: 7 additions & 1 deletion spec/fixtures/add-triage-labels/docs_pr_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"updated_at": "2020-12-08T01:24:55Z",
"closed_at": null,
"merged_at": null,
"labels": []
"labels": [],
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
}
},
"repository": {
"id": 9384267,
Expand Down
8 changes: 7 additions & 1 deletion spec/fixtures/add-triage-labels/test_pr_opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"updated_at": "2020-12-08T01:24:55Z",
"closed_at": null,
"merged_at": null,
"labels": []
"labels": [],
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
}
},
"repository": {
"id": 9384267,
Expand Down
3 changes: 3 additions & 0 deletions src/add-triage-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export function addBasicPRLabels(probot: Probot) {
probot.on(['pull_request.opened', 'pull_request.edited'], async context => {
const { pull_request: pr } = context.payload;

// Only add triage labels to the default branch.
if (pr.base.ref !== pr.base.repo.default_branch) return;

const hasSemverLabel = pr.labels.some((l: any) => {
l.name.startsWith(SEMVER_PREFIX);
});
Expand Down

0 comments on commit f3a252d

Please sign in to comment.