Skip to content

Commit 94a6359

Browse files
authored
Merge pull request #12153 from github/repo-sync
repo sync
2 parents d5babbf + 4e7dd89 commit 94a6359

3 files changed

Lines changed: 50 additions & 21 deletions

File tree

.github/actions-scripts/enable-automerge.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { getOctokit } from '@actions/github'
2-
const token = process.env.GITHUB_TOKEN
3-
const prNumber = process.env.AUTOMERGE_PR_NUMBER
4-
const [org, repo] = process.env.GITHUB_REPOSITORY.split('/')
5-
const github = getOctokit(token)
62

73
main()
84
async function main() {
5+
const [org, repo] = process.env.GITHUB_REPOSITORY.split('/')
6+
if (!org || !repo) {
7+
throw new Error('GITHUB_REPOSITORY environment variable not set')
8+
}
9+
const prNumber = process.env.AUTOMERGE_PR_NUMBER
10+
if (!prNumber) {
11+
throw new Error(`AUTOMERGE_PR_NUMBER environment variable not set`)
12+
}
13+
const token = process.env.GITHUB_TOKEN
14+
if (!token) {
15+
throw new Error(`GITHUB_TOKEN environment variable not set`)
16+
}
17+
const github = getOctokit(token)
918
const pull = await github.rest.pulls.get({
1019
owner: org,
1120
repo: repo,

.github/actions-scripts/update-merge-queue-branch.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ const github = getOctokit(token)
2020
main()
2121

2222
async function main() {
23+
const [org, repo] = process.env.GITHUB_REPOSITORY.split('/')
24+
if (!org || !repo) {
25+
throw new Error('GITHUB_REPOSITORY environment variable not set')
26+
}
2327
// Get a list of open PRs and order them from oldest to newest
24-
const query = `query ($first: Int, $after: String, $firstLabels: Int) {
25-
organization(login: "github") {
26-
repository(name: "docs-internal") {
28+
const query = `query ($first: Int, $after: String, $firstLabels: Int, $repo: String!, $org: String!) {
29+
organization(login: $org) {
30+
repository(name: $repo) {
2731
pullRequests(first: $first, after: $after, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
2832
edges{
2933
node {
@@ -55,6 +59,8 @@ async function main() {
5559
}`
5660

5761
const queryVariables = {
62+
repo,
63+
org,
5864
first: 100,
5965
after: null, // when pagination in null it will get first page
6066
firstLabels: 100,
@@ -105,20 +111,25 @@ async function main() {
105111

106112
// Get the list of prs with the skip label so they can
107113
// be put at the beginning of the list
108-
const prioritizedPrList = autoMergeEnabledPRs
109-
.filter((pr) => pr.labels.includes('skip-to-front-of-merge-queue'))
110-
.concat(autoMergeEnabledPRs.filter((pr) => !pr.labels.includes('skip-to-front-of-merge-queue')))
114+
const prioritizedPrList = autoMergeEnabledPRs.sort(
115+
(a, b) =>
116+
Number(b.labels.includes('skip-to-front-of-merge-queue')) -
117+
Number(a.labels.includes('skip-to-front-of-merge-queue'))
118+
)
111119

112-
const nextInQueue = prioritizedPrList.shift()
113-
// Update the branch for the next PR in the merge queue
114-
github.rest.pulls.updateBranch({
115-
owner: 'github',
116-
repo: 'docs-internal',
117-
pull_number: parseInt(nextInQueue.number),
118-
})
120+
if (prioritizedPrList.length) {
121+
const nextInQueue = prioritizedPrList.shift()
122+
// Update the branch for the next PR in the merge queue
123+
github.rest.pulls.updateBranch({
124+
owner: org,
125+
repo,
126+
pull_number: nextInQueue.number,
127+
})
128+
console.log(`⏱ Total PRs in the merge queue: ${prioritizedPrList.length + 1}`)
129+
console.log(`🚂 Updated branch for PR #${JSON.stringify(nextInQueue, null, 2)}`)
130+
}
119131

120-
console.log(`⏱ Total PRs in the merge queue: ${prioritizedPrList.length + 1}`)
121-
console.log(`🚂 Updated branch for PR #${JSON.stringify(nextInQueue, null, 2)}`)
122-
console.log(`🚏 Next up in the queue: `)
123-
console.log(JSON.stringify(prioritizedPrList, null, 2))
132+
prioritizedPrList.length
133+
? console.log(`🚏 Next up in the queue: \n ${JSON.stringify(prioritizedPrList, null, 2)}`)
134+
: console.log(`⚡ The merge queue is empty`)
124135
}

.github/workflows/autoupdate-branch.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030
name: autoupdate
3131
runs-on: ubuntu-latest
3232
steps:
33+
- name: Check out repo content
34+
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
35+
36+
- name: Setup Node
37+
uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c
38+
with:
39+
node-version: 16.13.x
40+
cache: npm
41+
3342
- name: Update next PR in queue
3443
env:
3544
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}

0 commit comments

Comments
 (0)