Skip to content

fix(cb2-8751): user has to refresh the page to view amended details #12

fix(cb2-8751): user has to refresh the page to view amended details

fix(cb2-8751): user has to refresh the page to view amended details #12

name: Tag Merge Conflicts
on:
push:
branches: ['develop']
pull_request:
branches: ['develop']
jobs:
merge-conflicts:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v6
with:
script: |
const pullRequests = (await github.rest.pulls.list({
...context.repo
})).data
const addMergeConflictTag = async (pullRequests) => {
const promises = pullRequests.map(pr => {
const { number } = pr
return github.rest.pulls.get({
...context.repo,
pull_number: number
})
})
const prs = await Promise.allSettled(promises)
const prsAwaitingCheck = []
prs.forEach(pr => {
const data = pr.value.data
if (data.mergeable === false) {
github.rest.issues.addLabels({
...context.repo,
issue_number: data.number,
labels: ["merge conflict"]
})
} else if (data.mergeable === true
&& data.labels.some(label => label.name === "merge conflict")) {
github.rest.issues.removeLabel({
...context.repo,
issue_number: data.number,
name: "merge conflict"
})
} else if (data.mergeable === null) {
prsAwaitingCheck.push({...data})
}
})
if (prsAwaitingCheck.length) {
console.log("Some PRs are still waiting to calculate status...")
await new Promise(resolve => setTimeout(resolve, 5000))
addMergeConflictTag(prsAwaitingCheck)
}
}
await addMergeConflictTag(pullRequests)