Skip to content

Commit d4687bb

Browse files
committed
Fix branch protection updates if there are no matching protections
1 parent 5012084 commit d4687bb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/branch-protection.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ module.exports = async function (owner, repo, old, target, octokit) {
1717
} = await octokit.graphql(query, { owner, repo });
1818

1919
// there can only be one protection per pattern
20-
const { id } = branchProtectionRules.find((rule) => rule.pattern === old);
20+
const rule = branchProtectionRules.find((rule) => rule.pattern === old);
21+
22+
// No matching patterns
23+
if (!rule) {
24+
return;
25+
}
26+
2127
await octokit.graphql(
2228
`mutation($branchProtectionRuleId:ID!,$pattern:String!) {
2329
updateBranchProtectionRule (input:{branchProtectionRuleId:$branchProtectionRuleId,pattern:$pattern}) {
@@ -28,7 +34,7 @@ module.exports = async function (owner, repo, old, target, octokit) {
2834
}
2935
}`,
3036
{
31-
branchProtectionRuleId: id,
37+
branchProtectionRuleId: rule.id,
3238
pattern: target,
3339
}
3440
);

0 commit comments

Comments
 (0)