Skip to content

Commit

Permalink
make action more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
albertmink committed Mar 19, 2024
1 parent d06b61d commit 70103dc
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/json-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,38 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const labelName = "incompatible-changes"; // replace with your label name
try {
// Try to remove the label
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: labelName,
});
console.log(`Label '${labelName}' has been removed`);
} catch (error) {
// If the label does not exist, do nothing and log a message
if (error.status === 404) {
console.log(`Label '${labelName}' does not exist, nothing to do`);
} else {
// If it's another type of error, re-throw to see the error details in the workflow log
throw error;
}
}
github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'incompatible-changes',
name: labelName,
color: 'FF0000'
}).catch(err => console.log(`Label already exists`))
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'incompatible-changes'
name: labelName
})
github-token: ${{secrets.GITHUB_TOKEN}}

0 comments on commit 70103dc

Please sign in to comment.