fix(tools): implement better error handling (#41379)
* fix(tools): implement better error handling Modifies the workflow to validate the branch exists and the PR does not. This was not blocking any issues, but caused the action to report a failure. * fix: apply Randy's review suggestions Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
16e420021c
commit
55dfa28359
@ -90,6 +90,25 @@ jobs:
|
||||
with:
|
||||
github-token: ${{ secrets.CROWDIN_CAMPERBOT_PAT }}
|
||||
script: |
|
||||
const branchExists = await github.repos.getBranch({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
branch: 'i18n-sync-client'
|
||||
}).catch(err => {
|
||||
console.info("Branch does not exist. Likely no changes in download?");
|
||||
});
|
||||
if (!branchExists || branchExists.status !== 200) {
|
||||
return;
|
||||
}
|
||||
const pullRequestExists = await github.pulls.list({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
head: 'freeCodeCamp:i18n-sync-client'
|
||||
});
|
||||
if (pullRequestExists.data.length) {
|
||||
console.info("It looks like a pull request already exists for this branch.");
|
||||
return;
|
||||
}
|
||||
const PR = await github.pulls.create({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
@ -97,7 +116,13 @@ jobs:
|
||||
base: 'main',
|
||||
title: 'chore(i18n,client): processed translations',
|
||||
body: 'This PR was opened auto-magically by Crowdin.'
|
||||
}).catch(err => {
|
||||
console.info("Unpredicted error occurred when trying to create the PR.");
|
||||
console.error(err);
|
||||
});
|
||||
if (!PR || PR.status !== 201) {
|
||||
return;
|
||||
}
|
||||
const PRNumber = PR.data.number;
|
||||
await github.issues.addLabels({
|
||||
owner: 'freeCodeCamp',
|
||||
|
@ -91,6 +91,25 @@ jobs:
|
||||
with:
|
||||
github-token: ${{ secrets.CROWDIN_CAMPERBOT_PAT }}
|
||||
script: |
|
||||
const branchExists = await github.repos.getBranch({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
branch: 'i18n-sync-learn'
|
||||
}).catch(err => {
|
||||
console.info("Branch does not exist. Likely no changes in download?");
|
||||
});
|
||||
if (!branchExists || branchExists.status !== 200) {
|
||||
return;
|
||||
}
|
||||
const pullRequestExists = await github.pulls.list({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
head: 'freeCodeCamp:i18n-sync-learn'
|
||||
});
|
||||
if (pullRequestExists.data.length) {
|
||||
console.info("It looks like a pull request already exists for this branch.");
|
||||
return;
|
||||
}
|
||||
const PR = await github.pulls.create({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
@ -98,7 +117,13 @@ jobs:
|
||||
base: 'main',
|
||||
title: 'chore(i18n,learn): processed translations',
|
||||
body: 'This PR was opened auto-magically by Crowdin.'
|
||||
}).catch(err => {
|
||||
console.info("Unpredicted error occurred when trying to create the PR.");
|
||||
console.error(err);
|
||||
});
|
||||
if (!PR || PR.status !== 201) {
|
||||
return;
|
||||
}
|
||||
const PRNumber = PR.data.number;
|
||||
await github.issues.addLabels({
|
||||
owner: 'freeCodeCamp',
|
||||
|
@ -124,6 +124,25 @@ jobs:
|
||||
with:
|
||||
github-token: ${{ secrets.CROWDIN_CAMPERBOT_PAT }}
|
||||
script: |
|
||||
const branchExists = await github.repos.getBranch({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
branch: 'i18n-sync-docs'
|
||||
}).catch(err => {
|
||||
console.info("Branch does not exist. Likely no changes in download?");
|
||||
});
|
||||
if (!branchExists || branchExists.status !== 200) {
|
||||
return;
|
||||
}
|
||||
const pullRequestExists = await github.pulls.list({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
head: 'freeCodeCamp:i18n-sync-docs'
|
||||
});
|
||||
if (pullRequestExists.data.length) {
|
||||
console.info("It looks like a pull request already exists for this branch.");
|
||||
return;
|
||||
}
|
||||
const PR = await github.pulls.create({
|
||||
owner: 'freeCodeCamp',
|
||||
repo: 'freeCodeCamp',
|
||||
@ -131,7 +150,13 @@ jobs:
|
||||
base: 'main',
|
||||
title: 'chore(i18n,docs): processed translations',
|
||||
body: 'This PR was opened auto-magically by Crowdin.'
|
||||
}).catch(err => {
|
||||
console.info("Unpredicted error occurred when trying to create the PR.");
|
||||
console.error(err);
|
||||
});
|
||||
if (!PR || PR.status !== 201) {
|
||||
return;
|
||||
}
|
||||
const PRNumber = PR.data.number;
|
||||
await github.issues.addLabels({
|
||||
owner: 'freeCodeCamp',
|
||||
|
Reference in New Issue
Block a user