Skip to content

Commit 7657e4d

Browse files
committed
Optionally override the active GitHub App via the environment
To support embargoed builds in a private fork, we need to be able to do things outside of the regular `git-for-windows` org. This also requires a GitHub App to be installed on that org, and to allow for developing that App separately from the public one (so that urgent fixes can be made in private, without notifying anyone of ongoing security work), it must be a GitHub App other than the one that is installed in the `git-for-windows` org. Also fix the check_run tests to use `sender.login: 'ghost'`, which is what GitHub actually sends for check runs created via the API by an app nowadays (yes, this changed at some stage, and we had to adapt). Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 239bbf8 commit 7657e4d

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

GitForWindowsHelper/cascading-runs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { activeOrg } = require('./org')
1+
const { activeBot, activeOrg } = require('./org')
22

33
const getToken = (() => {
44
const tokens = {}
@@ -14,7 +14,7 @@ const getToken = (() => {
1414
})()
1515

1616
const isAllowed = async (context, owner, repo, login) => {
17-
if (login === 'gitforwindowshelper[bot]') return true
17+
if (login === `${activeBot}[bot]`) return true
1818
const getCollaboratorPermissions = require('./get-collaborator-permissions')
1919
const token = await getToken(context, owner, repo)
2020
const permission = await getCollaboratorPermissions(context, token, owner, repo, login)
@@ -117,8 +117,8 @@ const cascadingRuns = async (context, req) => {
117117
const checkRunRepo = req.body.repository.name
118118
const checkRun = req.body.check_run
119119
const name = checkRun.name
120-
const sender = req.body.sender.login === 'ghost' && checkRun?.app?.slug === 'gitforwindowshelper'
121-
? 'gitforwindowshelper[bot]' : req.body.sender.login
120+
const sender = req.body.sender.login === 'ghost' && checkRun?.app?.slug === activeBot
121+
? `${activeBot}[bot]` : req.body.sender.login
122122

123123
if (action === 'completed') {
124124
if (name === 'tag-git') {

GitForWindowsHelper/finalize-g4w-release.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { activeOrg } = require('./org')
1+
const { activeOrg, activeBot } = require('./org')
22

33
module.exports = async (context, req) => {
44
if (req.body.action !== 'completed') return "Nothing to do here: workflow run did not complete yet"
@@ -23,7 +23,7 @@ module.exports = async (context, req) => {
2323
})()
2424

2525
const isAllowed = async (login) => {
26-
if (login === 'gitforwindowshelper[bot]') return true
26+
if (login === `${activeBot}[bot]`) return true
2727
const getCollaboratorPermissions = require('./get-collaborator-permissions')
2828
const token = await getToken()
2929
const permission = await getCollaboratorPermissions(context, token, owner, repo, login)

GitForWindowsHelper/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const validateGitHubWebHook = require('./validate-github-webhook')
2-
const { activeOrg } = require('./org')
2+
const { activeBot, activeOrg } = require('./org')
33

44
module.exports = async function (context, req) {
55
const withStatus = (status, headers, body) => {
@@ -54,7 +54,7 @@ module.exports = async function (context, req) {
5454
try {
5555
const { cascadingRuns, handlePush } = require('./cascading-runs.js')
5656
if (req.headers['x-github-event'] === 'check_run'
57-
&& req.body.check_run?.app?.slug === 'gitforwindowshelper'
57+
&& req.body.check_run?.app?.slug === activeBot
5858
&& req.body.repository.full_name === `${activeOrg}/git`
5959
&& req.body.action === 'completed') return ok(await cascadingRuns(context, req))
6060

GitForWindowsHelper/org.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
2-
activeOrg: process.env.ACTIVE_ORG || 'git-for-windows'
2+
activeOrg: process.env.ACTIVE_ORG || 'git-for-windows',
3+
activeBot: process.env.ACTIVE_BOT || 'gitforwindowshelper',
34
}

__tests__/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ test('a completed `tag-git` run triggers `git-artifacts` runs', async () => {
798798
slug: 'gitforwindowshelper',
799799
},
800800
},
801+
sender: {
802+
login: 'ghost'
803+
},
801804
installation: {
802805
id: 123
803806
},
@@ -999,6 +1002,9 @@ test('the third completed `git-artifacts-<arch>` check-run triggers an `upload-s
9991002
slug: 'gitforwindowshelper',
10001003
},
10011004
},
1005+
sender: {
1006+
login: 'ghost'
1007+
},
10021008
installation: {
10031009
id: 123
10041010
},

0 commit comments

Comments
 (0)