Compare commits
10 Commits
v4
...
v4-graphql
Author | SHA1 | Date | |
---|---|---|---|
0bc3ec0e0a | |||
36a56dac07 | |||
b7f0c9773b | |||
6a62596740 | |||
d1ed29fe1e | |||
e34fedf492 | |||
495ffbb489 | |||
073c8e6ece | |||
375254568c | |||
09af4e30b5 |
2
.github/workflows/automerge-dependabot.yml
vendored
2
.github/workflows/automerge-dependabot.yml
vendored
@ -6,7 +6,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- uses: peter-evans/enable-pull-request-automerge@v2
|
||||
- uses: peter-evans/enable-pull-request-automerge@v3
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
pull-request-number: ${{ github.event.pull_request.number }}
|
||||
|
103
dist/index.js
vendored
103
dist/index.js
vendored
@ -1074,10 +1074,10 @@ class GitHubHelper {
|
||||
requestReviewersParams['reviewers'] = inputs.reviewers;
|
||||
core.info(`Requesting reviewers '${inputs.reviewers}'`);
|
||||
}
|
||||
if (inputs.teamReviewers.length > 0) {
|
||||
requestReviewersParams['team_reviewers'] = inputs.teamReviewers;
|
||||
core.info(`Requesting team reviewers '${inputs.teamReviewers}'`);
|
||||
}
|
||||
// if (inputs.teamReviewers.length > 0) {
|
||||
// requestReviewersParams['team_reviewers'] = inputs.teamReviewers
|
||||
// core.info(`Requesting team reviewers '${inputs.teamReviewers}'`)
|
||||
// }
|
||||
if (Object.keys(requestReviewersParams).length > 0) {
|
||||
try {
|
||||
yield this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
|
||||
@ -1091,9 +1091,104 @@ class GitHubHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
const orgs = inputs.teamReviewers.map(team => {
|
||||
if (!team.includes('/')) {
|
||||
throw new Error(`Team ${team} is not in the correct format. It should be in the format org/team`);
|
||||
}
|
||||
return team.split('/')[0];
|
||||
});
|
||||
const distinctOrgs = [...new Set(orgs)];
|
||||
core.debug(`distinctOrgs: ${distinctOrgs}`);
|
||||
const orgTeams = yield Promise.all(distinctOrgs.map(org => this.getOrgTeams(org)));
|
||||
const teamIds = inputs.teamReviewers.map(team => {
|
||||
var _a;
|
||||
const [org, teamName] = team.split('/');
|
||||
const orgTeam = orgTeams.find(orgTeam => orgTeam.organization.login === org);
|
||||
if (!orgTeam) {
|
||||
throw new Error(`Org ${org} not found`);
|
||||
}
|
||||
const teamId = (_a = orgTeam.organization.teams.edges.find(team => team.node.slug === teamName)) === null || _a === void 0 ? void 0 : _a.node.id;
|
||||
if (!teamId) {
|
||||
throw new Error(`Team ${teamName} not found in ${org}`);
|
||||
}
|
||||
return teamId;
|
||||
});
|
||||
core.debug(`teamIds: ${teamIds}`);
|
||||
if (teamIds.length > 0) {
|
||||
const repository = this.parseRepository(baseRepository);
|
||||
const pullNodeId = yield this.getPullNodeId(repository.owner, repository.repo, pull.number);
|
||||
core.debug(`pullNodeId: ${pullNodeId}`);
|
||||
yield this.requestReviewers(pullNodeId, teamIds);
|
||||
}
|
||||
return pull;
|
||||
});
|
||||
}
|
||||
getOrgTeams(orgName) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const query = `
|
||||
query($orgName: String!, $teamCount: Int!) {
|
||||
organization(login: $orgName) {
|
||||
login
|
||||
teams(first: $teamCount) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const teamCount = 100;
|
||||
return this.octokit.graphql(query, {
|
||||
orgName,
|
||||
teamCount
|
||||
});
|
||||
});
|
||||
}
|
||||
getPullNodeId(owner, repo, pullNumber) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const query = `
|
||||
query($owner: String!, $repo: String!) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
pullRequest(number: ${pullNumber}) {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
return (yield this.octokit.graphql(query, {
|
||||
owner,
|
||||
repo
|
||||
})).repository.pullRequest.id;
|
||||
});
|
||||
}
|
||||
requestReviewers(pullRequestId, teamIds) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const mutation = `
|
||||
mutation($input: RequestReviewsInput!) {
|
||||
requestReviews(input: $input) {
|
||||
clientMutationId
|
||||
}
|
||||
}
|
||||
`;
|
||||
yield this.octokit
|
||||
.graphql(mutation, {
|
||||
input: {
|
||||
pullRequestId,
|
||||
teamIds: teamIds,
|
||||
union: true
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
core.info('Reviews requested successfully');
|
||||
})
|
||||
.catch(error => {
|
||||
core.error(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.GitHubHelper = GitHubHelper;
|
||||
|
||||
|
150
package-lock.json
generated
150
package-lock.json
generated
@ -18,20 +18,20 @@
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.1",
|
||||
"@types/node": "^18.15.3",
|
||||
"@typescript-eslint/parser": "^5.55.0",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.15.10",
|
||||
"@typescript-eslint/parser": "^5.57.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.36.0",
|
||||
"eslint-import-resolver-typescript": "^3.5.3",
|
||||
"eslint-plugin-github": "^4.6.1",
|
||||
"eslint-plugin-github": "^4.7.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"jest": "^29.5.0",
|
||||
"jest-circus": "^29.4.2",
|
||||
"jest-environment-jsdom": "^29.5.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier": "^2.8.7",
|
||||
"ts-jest": "^29.0.5",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
@ -1523,9 +1523,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/jest": {
|
||||
"version": "29.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.4.1.tgz",
|
||||
"integrity": "sha512-zDQSWXG+ZkEvs2zFFMszePhx4euKz+Yt3Gg1P+RHjfJBinTTr6L2DEyovO4V/WrKXuF0Dgn56GWGZPDa6TW9eQ==",
|
||||
"version": "29.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.0.tgz",
|
||||
"integrity": "sha512-3Emr5VOl/aoBwnWcH/EFQvlSAmjV+XtV9GGu5mwdYew5vhQh0IUZx/60x0TzHDu09Bi7HMx10t/namdJw5QIcg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"expect": "^29.0.0",
|
||||
@ -1556,9 +1556,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.15.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.3.tgz",
|
||||
"integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==",
|
||||
"version": "18.15.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.10.tgz",
|
||||
"integrity": "sha512-9avDaQJczATcXgfmMAW3MIWArOO7A+m90vuCFLr8AotWf8igO/mRoYukrk2cqZVtv38tHs33retzHEilM7FpeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/prettier": {
|
||||
@ -1673,14 +1673,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.55.0.tgz",
|
||||
"integrity": "sha512-ppvmeF7hvdhUUZWSd2EEWfzcFkjJzgNQzVST22nzg958CR+sphy8A6K7LXQZd6V75m1VKjp+J4g/PCEfSCmzhw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.57.0.tgz",
|
||||
"integrity": "sha512-orrduvpWYkgLCyAdNtR1QIWovcNZlEm6yL8nwH/eTxWLd8gsP+25pdLHYzL2QdkqrieaDwLpytHqycncv0woUQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "5.55.0",
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/typescript-estree": "5.55.0",
|
||||
"@typescript-eslint/scope-manager": "5.57.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/typescript-estree": "5.57.0",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@ -1700,13 +1700,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.55.0.tgz",
|
||||
"integrity": "sha512-OK+cIO1ZGhJYNCL//a3ROpsd83psf4dUJ4j7pdNVzd5DmIk+ffkuUIX2vcZQbEW/IR41DYsfJTB19tpCboxQuw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.57.0.tgz",
|
||||
"integrity": "sha512-NANBNOQvllPlizl9LatX8+MHi7bx7WGIWYjPHDmQe5Si/0YEYfxSljJpoTyTWFTgRy3X8gLYSE4xQ2U+aCozSw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/visitor-keys": "5.55.0"
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/visitor-keys": "5.57.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@ -1717,9 +1717,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.55.0.tgz",
|
||||
"integrity": "sha512-M4iRh4AG1ChrOL6Y+mETEKGeDnT7Sparn6fhZ5LtVJF1909D5O4uqK+C5NPbLmpfZ0XIIxCdwzKiijpZUOvOug==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.57.0.tgz",
|
||||
"integrity": "sha512-mxsod+aZRSyLT+jiqHw1KK6xrANm19/+VFALVFP5qa/aiJnlP38qpyaTd0fEKhWvQk6YeNZ5LGwI1pDpBRBhtQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@ -1730,13 +1730,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.55.0.tgz",
|
||||
"integrity": "sha512-I7X4A9ovA8gdpWMpr7b1BN9eEbvlEtWhQvpxp/yogt48fy9Lj3iE3ild/1H3jKBBIYj5YYJmS2+9ystVhC7eaQ==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.57.0.tgz",
|
||||
"integrity": "sha512-LTzQ23TV82KpO8HPnWuxM2V7ieXW8O142I7hQTxWIHDcCEIjtkat6H96PFkYBQqGFLW/G/eVVOB9Z8rcvdY/Vw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/visitor-keys": "5.55.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/visitor-keys": "5.57.0",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
@ -1757,12 +1757,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.55.0.tgz",
|
||||
"integrity": "sha512-q2dlHHwWgirKh1D3acnuApXG+VNXpEY5/AwRxDVuEQpxWaB0jCDe0jFMVMALJ3ebSfuOVE8/rMS+9ZOYGg1GWw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.57.0.tgz",
|
||||
"integrity": "sha512-ery2g3k0hv5BLiKpPuwYt9KBkAp2ugT6VvyShXdLOkax895EC55sP0Tx5L0fZaQueiK3fBLvHVvEl3jFS5ia+g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
@ -3402,9 +3402,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-github": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.6.1.tgz",
|
||||
"integrity": "sha512-AjCxE+2JmT+ppq3AVNra3iJ0BTAj6rYmtHJtkEcIEtrBHVi9xmCl5ZdIYLh7U/YKGT2cttdcYvbe59HEYW67KA==",
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.7.0.tgz",
|
||||
"integrity": "sha512-SIFSy6IXtN3aGQ6YyFWg/oxRUyAcYwg5G0wh+ov1HQCvmp+Pzs1GzeVjU8QcIQSSJfverQzuxWrJCAln/d2PuQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@github/browserslist-config": "^1.0.0",
|
||||
@ -6403,9 +6403,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.8.4",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz",
|
||||
"integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==",
|
||||
"version": "2.8.7",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
|
||||
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
@ -8985,9 +8985,9 @@
|
||||
}
|
||||
},
|
||||
"@types/jest": {
|
||||
"version": "29.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.4.1.tgz",
|
||||
"integrity": "sha512-zDQSWXG+ZkEvs2zFFMszePhx4euKz+Yt3Gg1P+RHjfJBinTTr6L2DEyovO4V/WrKXuF0Dgn56GWGZPDa6TW9eQ==",
|
||||
"version": "29.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.0.tgz",
|
||||
"integrity": "sha512-3Emr5VOl/aoBwnWcH/EFQvlSAmjV+XtV9GGu5mwdYew5vhQh0IUZx/60x0TzHDu09Bi7HMx10t/namdJw5QIcg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"expect": "^29.0.0",
|
||||
@ -9018,9 +9018,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "18.15.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.3.tgz",
|
||||
"integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==",
|
||||
"version": "18.15.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.10.tgz",
|
||||
"integrity": "sha512-9avDaQJczATcXgfmMAW3MIWArOO7A+m90vuCFLr8AotWf8igO/mRoYukrk2cqZVtv38tHs33retzHEilM7FpeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/prettier": {
|
||||
@ -9105,41 +9105,41 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/parser": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.55.0.tgz",
|
||||
"integrity": "sha512-ppvmeF7hvdhUUZWSd2EEWfzcFkjJzgNQzVST22nzg958CR+sphy8A6K7LXQZd6V75m1VKjp+J4g/PCEfSCmzhw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.57.0.tgz",
|
||||
"integrity": "sha512-orrduvpWYkgLCyAdNtR1QIWovcNZlEm6yL8nwH/eTxWLd8gsP+25pdLHYzL2QdkqrieaDwLpytHqycncv0woUQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/scope-manager": "5.55.0",
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/typescript-estree": "5.55.0",
|
||||
"@typescript-eslint/scope-manager": "5.57.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/typescript-estree": "5.57.0",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.55.0.tgz",
|
||||
"integrity": "sha512-OK+cIO1ZGhJYNCL//a3ROpsd83psf4dUJ4j7pdNVzd5DmIk+ffkuUIX2vcZQbEW/IR41DYsfJTB19tpCboxQuw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.57.0.tgz",
|
||||
"integrity": "sha512-NANBNOQvllPlizl9LatX8+MHi7bx7WGIWYjPHDmQe5Si/0YEYfxSljJpoTyTWFTgRy3X8gLYSE4xQ2U+aCozSw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/visitor-keys": "5.55.0"
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/visitor-keys": "5.57.0"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/types": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.55.0.tgz",
|
||||
"integrity": "sha512-M4iRh4AG1ChrOL6Y+mETEKGeDnT7Sparn6fhZ5LtVJF1909D5O4uqK+C5NPbLmpfZ0XIIxCdwzKiijpZUOvOug==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.57.0.tgz",
|
||||
"integrity": "sha512-mxsod+aZRSyLT+jiqHw1KK6xrANm19/+VFALVFP5qa/aiJnlP38qpyaTd0fEKhWvQk6YeNZ5LGwI1pDpBRBhtQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/typescript-estree": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.55.0.tgz",
|
||||
"integrity": "sha512-I7X4A9ovA8gdpWMpr7b1BN9eEbvlEtWhQvpxp/yogt48fy9Lj3iE3ild/1H3jKBBIYj5YYJmS2+9ystVhC7eaQ==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.57.0.tgz",
|
||||
"integrity": "sha512-LTzQ23TV82KpO8HPnWuxM2V7ieXW8O142I7hQTxWIHDcCEIjtkat6H96PFkYBQqGFLW/G/eVVOB9Z8rcvdY/Vw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/visitor-keys": "5.55.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"@typescript-eslint/visitor-keys": "5.57.0",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
@ -9148,12 +9148,12 @@
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/visitor-keys": {
|
||||
"version": "5.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.55.0.tgz",
|
||||
"integrity": "sha512-q2dlHHwWgirKh1D3acnuApXG+VNXpEY5/AwRxDVuEQpxWaB0jCDe0jFMVMALJ3ebSfuOVE8/rMS+9ZOYGg1GWw==",
|
||||
"version": "5.57.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.57.0.tgz",
|
||||
"integrity": "sha512-ery2g3k0hv5BLiKpPuwYt9KBkAp2ugT6VvyShXdLOkax895EC55sP0Tx5L0fZaQueiK3fBLvHVvEl3jFS5ia+g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "5.55.0",
|
||||
"@typescript-eslint/types": "5.57.0",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
}
|
||||
}
|
||||
@ -10371,9 +10371,9 @@
|
||||
}
|
||||
},
|
||||
"eslint-plugin-github": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.6.1.tgz",
|
||||
"integrity": "sha512-AjCxE+2JmT+ppq3AVNra3iJ0BTAj6rYmtHJtkEcIEtrBHVi9xmCl5ZdIYLh7U/YKGT2cttdcYvbe59HEYW67KA==",
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.7.0.tgz",
|
||||
"integrity": "sha512-SIFSy6IXtN3aGQ6YyFWg/oxRUyAcYwg5G0wh+ov1HQCvmp+Pzs1GzeVjU8QcIQSSJfverQzuxWrJCAln/d2PuQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@github/browserslist-config": "^1.0.0",
|
||||
@ -12580,9 +12580,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"prettier": {
|
||||
"version": "2.8.4",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz",
|
||||
"integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==",
|
||||
"version": "2.8.7",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
|
||||
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
|
||||
"dev": true
|
||||
},
|
||||
"prettier-linter-helpers": {
|
||||
|
10
package.json
10
package.json
@ -38,20 +38,20 @@
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.1",
|
||||
"@types/node": "^18.15.3",
|
||||
"@typescript-eslint/parser": "^5.55.0",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.15.10",
|
||||
"@typescript-eslint/parser": "^5.57.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.36.0",
|
||||
"eslint-import-resolver-typescript": "^3.5.3",
|
||||
"eslint-plugin-github": "^4.6.1",
|
||||
"eslint-plugin-github": "^4.7.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"jest": "^29.5.0",
|
||||
"jest-circus": "^29.4.2",
|
||||
"jest-environment-jsdom": "^29.5.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier": "^2.8.7",
|
||||
"ts-jest": "^29.0.5",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
|
@ -158,10 +158,10 @@ export class GitHubHelper {
|
||||
requestReviewersParams['reviewers'] = inputs.reviewers
|
||||
core.info(`Requesting reviewers '${inputs.reviewers}'`)
|
||||
}
|
||||
if (inputs.teamReviewers.length > 0) {
|
||||
requestReviewersParams['team_reviewers'] = inputs.teamReviewers
|
||||
core.info(`Requesting team reviewers '${inputs.teamReviewers}'`)
|
||||
}
|
||||
// if (inputs.teamReviewers.length > 0) {
|
||||
// requestReviewersParams['team_reviewers'] = inputs.teamReviewers
|
||||
// core.info(`Requesting team reviewers '${inputs.teamReviewers}'`)
|
||||
// }
|
||||
if (Object.keys(requestReviewersParams).length > 0) {
|
||||
try {
|
||||
await this.octokit.rest.pulls.requestReviewers({
|
||||
@ -178,6 +178,147 @@ export class GitHubHelper {
|
||||
}
|
||||
}
|
||||
|
||||
const orgs = inputs.teamReviewers.map(team => {
|
||||
if (!team.includes('/')) {
|
||||
throw new Error(
|
||||
`Team ${team} is not in the correct format. It should be in the format org/team`
|
||||
)
|
||||
}
|
||||
return team.split('/')[0]
|
||||
})
|
||||
const distinctOrgs = [...new Set(orgs)]
|
||||
core.debug(`distinctOrgs: ${distinctOrgs}`)
|
||||
|
||||
const orgTeams = await Promise.all(
|
||||
distinctOrgs.map(org => this.getOrgTeams(org))
|
||||
)
|
||||
|
||||
const teamIds = inputs.teamReviewers.map(team => {
|
||||
const [org, teamName] = team.split('/')
|
||||
const orgTeam = orgTeams.find(
|
||||
orgTeam => orgTeam.organization.login === org
|
||||
)
|
||||
if (!orgTeam) {
|
||||
throw new Error(`Org ${org} not found`)
|
||||
}
|
||||
const teamId = orgTeam.organization.teams.edges.find(
|
||||
team => team.node.slug === teamName
|
||||
)?.node.id
|
||||
if (!teamId) {
|
||||
throw new Error(`Team ${teamName} not found in ${org}`)
|
||||
}
|
||||
return teamId
|
||||
})
|
||||
core.debug(`teamIds: ${teamIds}`)
|
||||
|
||||
if (teamIds.length > 0) {
|
||||
const repository = this.parseRepository(baseRepository)
|
||||
const pullNodeId = await this.getPullNodeId(
|
||||
repository.owner,
|
||||
repository.repo,
|
||||
pull.number
|
||||
)
|
||||
core.debug(`pullNodeId: ${pullNodeId}`)
|
||||
|
||||
await this.requestReviewers(pullNodeId, teamIds)
|
||||
}
|
||||
|
||||
return pull
|
||||
}
|
||||
|
||||
async getOrgTeams(orgName: string): Promise<OrgTeams> {
|
||||
const query = `
|
||||
query($orgName: String!, $teamCount: Int!) {
|
||||
organization(login: $orgName) {
|
||||
login
|
||||
teams(first: $teamCount) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const teamCount = 100
|
||||
return this.octokit.graphql<OrgTeams>(query, {
|
||||
orgName,
|
||||
teamCount
|
||||
})
|
||||
}
|
||||
|
||||
async getPullNodeId(
|
||||
owner: string,
|
||||
repo: string,
|
||||
pullNumber: number
|
||||
): Promise<string> {
|
||||
const query = `
|
||||
query($owner: String!, $repo: String!) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
pullRequest(number: ${pullNumber}) {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
return (
|
||||
await this.octokit.graphql<PullRequestResponse>(query, {
|
||||
owner,
|
||||
repo
|
||||
})
|
||||
).repository.pullRequest.id
|
||||
}
|
||||
|
||||
async requestReviewers(
|
||||
pullRequestId: string,
|
||||
teamIds: string[]
|
||||
): Promise<void> {
|
||||
const mutation = `
|
||||
mutation($input: RequestReviewsInput!) {
|
||||
requestReviews(input: $input) {
|
||||
clientMutationId
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
await this.octokit
|
||||
.graphql(mutation, {
|
||||
input: {
|
||||
pullRequestId,
|
||||
teamIds: teamIds,
|
||||
union: true
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
core.info('Reviews requested successfully')
|
||||
})
|
||||
.catch(error => {
|
||||
core.error(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
interface OrgTeams {
|
||||
organization: {
|
||||
login: string
|
||||
teams: {
|
||||
edges: {
|
||||
node: {
|
||||
id: string
|
||||
slug: string
|
||||
}
|
||||
}[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface PullRequestResponse {
|
||||
repository: {
|
||||
pullRequest: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user