generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/stage' into twp
- Loading branch information
Showing
221 changed files
with
12,147 additions
and
1,797 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Those env variables are set by an github action automatically | ||
// For local testing, you should test on your fork. | ||
const owner = process.env.REPO_OWNER || ''; // example owner: adobecom | ||
const repo = process.env.REPO_NAME || ''; // example repo name: milo | ||
const auth = process.env.GH_TOKEN || ''; // https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens | ||
|
||
const getLocalConfigs = () => { | ||
if (!owner || !repo || !auth) { | ||
throw new Error(`Create a .env file on the root of the project with credentials. | ||
Then run: node --env-file=.env .github/workflows/update-ims.js`); | ||
} | ||
|
||
const { Octokit } = require('@octokit/rest'); | ||
return { | ||
github: { rest: new Octokit({ auth }) }, | ||
context: { | ||
repo: { | ||
owner, | ||
repo, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
const slackNotification = (text, webhook) => { | ||
console.log(text); | ||
return fetch(webhook || process.env.MILO_RELEASE_SLACK_WH, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ text }), | ||
}); | ||
}; | ||
|
||
const addLabels = ({ pr, github, owner, repo }) => | ||
github.rest.issues | ||
.listLabelsOnIssue({ owner, repo, issue_number: pr.number }) | ||
.then(({ data }) => { | ||
pr.labels = data.map(({ name }) => name); | ||
return pr; | ||
}); | ||
|
||
const addFiles = ({ pr, github, owner, repo }) => | ||
github.rest.pulls | ||
.listFiles({ owner, repo, pull_number: pr.number }) | ||
.then(({ data }) => { | ||
pr.files = data.map(({ filename }) => filename); | ||
return pr; | ||
}); | ||
|
||
const getChecks = ({ pr, github, owner, repo }) => | ||
github.rest.checks | ||
.listForRef({ owner, repo, ref: pr.head.sha }) | ||
.then(({ data }) => { | ||
const checksByName = data.check_runs.reduce((map, check) => { | ||
if ( | ||
!map.has(check.name) || | ||
new Date(map.get(check.name).completed_at) < | ||
new Date(check.completed_at) | ||
) { | ||
map.set(check.name, check); | ||
} | ||
return map; | ||
}, new Map()); | ||
pr.checks = Array.from(checksByName.values()); | ||
return pr; | ||
}); | ||
|
||
const getReviews = ({ pr, github, owner, repo }) => | ||
github.rest.pulls | ||
.listReviews({ | ||
owner, | ||
repo, | ||
pull_number: pr.number, | ||
}) | ||
.then(({ data }) => { | ||
pr.reviews = data; | ||
return pr; | ||
}); | ||
|
||
module.exports = { | ||
getLocalConfigs, | ||
slackNotification, | ||
pulls: { addLabels, addFiles, getChecks, getReviews }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { getLocalConfigs } = require('./helpers.js'); | ||
const zeroImpactDirs = [ | ||
'.github', | ||
'.kodiak', | ||
'.vscode', | ||
'.test', | ||
'libs/mep', | ||
'.eslintrc.js', | ||
'CODEOWNERS', | ||
'web-test-runner.config.mjs', | ||
'LICENSE', | ||
'codecov.yaml', | ||
'.gitignore', | ||
]; | ||
const zeroImpactLabel = 'zero-impact'; | ||
|
||
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/label-zero-impact.js | ||
const main = async ({ github, context }) => { | ||
const number = context.issue?.number || process.env.ISSUE; | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
|
||
try { | ||
const { data: files } = await github.rest.pulls.listFiles({ | ||
owner, | ||
repo, | ||
pull_number: number, | ||
}); | ||
|
||
const isZeroImpactPR = files.every(({ filename }) => | ||
zeroImpactDirs.some((dir) => filename.startsWith(dir)) | ||
); | ||
console.log(`PR ${number} is zero impact: ${isZeroImpactPR}.`); | ||
if (isZeroImpactPR) { | ||
console.log('Adding zero-impact label to PR.'); | ||
await github.rest.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: number, | ||
labels: [zeroImpactLabel], | ||
}); | ||
} else { | ||
console.log('Removing zero-impact label from PR.'); | ||
await github.rest.issues.removeLabel({ | ||
owner, | ||
repo, | ||
issue_number: number, | ||
name: zeroImpactLabel, | ||
}); | ||
console.log('Posting a comment on the PR.'); | ||
await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: number, | ||
body: 'This PR does not qualify for the zero-impact label as it touches code outside of the allowed areas. The label is auto applied, do not manually apply the label.', | ||
}); | ||
} | ||
|
||
console.log('Process successfully executed.'); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
if (process.env.LOCAL_RUN) { | ||
const { github, context } = getLocalConfigs(); | ||
main({ | ||
github, | ||
context, | ||
}); | ||
} | ||
|
||
module.exports = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Add or remove zero impact label | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened, labeled, unlabeled] | ||
|
||
jobs: | ||
label: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
|
||
- name: Add the zero impact label | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
const main = require('./.github/workflows/label-zero-impact.js') | ||
main({ github, context }) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.