Skip to content
This repository was archived by the owner on Oct 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/rename-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ async function renameBranch (octokit, { owner, repo, current_name: currentName,
default_branch: name
})

// update branch protection patterns
const query = `{
repository(owner:"${owner}",name:"${repo}") {
branchProtectionRules(first:100) {
nodes {
id
pattern
}
}
}
}`
const {
data: { data: { repository: { branchProtectionRules: { nodes: branchProtectionRules } } } }
} = await octokit.request('POST /graphql', { query })

// there can only be one protection per pattern
const { id } = branchProtectionRules.find(rule => rule.pattern === currentName)
await octokit.request('POST /graphql', {
query: `mutation {
updateBranchProtectionRule (input:{branchProtectionRuleId:"${id}",pattern:"${name}"}) {
branchProtectionRule {
id,
pattern
}
}
}`
})

// Iterate trough all open pull requests with base = <currentName>
// and change base to <name>
const options = octokit.pullRequests.list.endpoint.merge({
Expand Down
Loading