-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 2503-add-server-timeout
Signed-off-by: ebadiere <ebadiere@gmail.com>
- Loading branch information
Showing
26 changed files
with
524 additions
and
239 deletions.
There are no files selected for viewing
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,66 @@ | ||
const axios = require('axios'); | ||
|
||
const githubToken = process.env.GITHUB_TOKEN; | ||
const { GITHUB_REPOSITORY, GITHUB_PR_NUMBER } = process.env; | ||
|
||
const [owner, repo] = GITHUB_REPOSITORY.split('/'); | ||
|
||
async function getPRDetails() { | ||
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${GITHUB_PR_NUMBER}`; | ||
const response = await axios.get(url, { | ||
headers: { | ||
Authorization: `token ${githubToken}` | ||
} | ||
}); | ||
return response.data; | ||
} | ||
|
||
async function getIssueDetails(issueNumber) { | ||
const url = `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`; | ||
const response = await axios.get(url, { | ||
headers: { | ||
Authorization: `token ${githubToken}` | ||
} | ||
}); | ||
return response.data; | ||
} | ||
|
||
async function run() { | ||
try { | ||
const pr = await getPRDetails(); | ||
const { labels: prLabels, milestone: prMilestone, body: prBody } = pr; | ||
|
||
if (prLabels.length === 0) { | ||
throw new Error('The PR has no labels.'); | ||
} | ||
if (!prMilestone) { | ||
throw new Error('The PR has no milestone.'); | ||
} | ||
|
||
const issueNumberMatches = prBody.match(/#(\d+)/g); | ||
|
||
if (!issueNumberMatches) { | ||
console.log('No associated issues found in PR description.'); | ||
} else { | ||
for (const match of issueNumberMatches) { | ||
const issueNumber = match.replace('#', ''); | ||
const issue = await getIssueDetails(issueNumber); | ||
const { labels: issueLabels, milestone: issueMilestone } = issue; | ||
|
||
if (issueLabels.length === 0) { | ||
throw new Error(`Associated issue #${issueNumber} has no labels.`); | ||
} | ||
if (!issueMilestone) { | ||
throw new Error(`Associated issue #${issueNumber} has no milestone.`); | ||
} | ||
} | ||
} | ||
|
||
console.log('PR and all associated issues have labels and milestones.'); | ||
} catch (error) { | ||
console.error(error.message); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
run(); |
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,27 @@ | ||
name: PR Label and Milestone Check | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, labeled, unlabeled, synchronize] | ||
|
||
jobs: | ||
check_pr: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install axios | ||
|
||
- name: Check PR labels and milestones | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_PR_NUMBER: ${{ github.event.number }} | ||
run: node .github/scripts/check-pr.js |
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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
Oops, something went wrong.