Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/stage' into twp
Browse files Browse the repository at this point in the history
  • Loading branch information
yesil committed May 21, 2024
2 parents 2058351 + ce419e7 commit c58efb0
Show file tree
Hide file tree
Showing 221 changed files with 12,147 additions and 1,797 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/auto-merge-main-to-stage.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: dorny/paths-filter@v2
id: changes
with:
base: ${{ github.ref }}
filters: |
src:
- 'libs/**'
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/email-release.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/enforce-labels.yml

This file was deleted.

86 changes: 86 additions & 0 deletions .github/workflows/helpers.js
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 },
};
73 changes: 73 additions & 0 deletions .github/workflows/label-zero-impact.js
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;
20 changes: 20 additions & 0 deletions .github/workflows/label-zero-impact.yaml
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 })
25 changes: 0 additions & 25 deletions .github/workflows/localWorkflowConfigs.js

This file was deleted.

Loading

0 comments on commit c58efb0

Please sign in to comment.