Skip to content

Commit 813df15

Browse files
authored
Merge pull request #155 from git-for-windows/get-event-payload-by-repo
get-webhook-event-payload: allow filtering by repository
2 parents 9ce1eaf + 28410d8 commit 813df15

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

get-webhook-event-payload.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
let eventType = undefined
77
let aroundDate = undefined
8+
let repository = undefined
89

910
// parse arguments, e.g. --event-type=check_run --date='Tue, 21 Nov 2023 11:13:12 GMT'
1011
const args = process.argv.slice(2)
@@ -37,7 +38,8 @@
3738
const arg = getArg()
3839
if (isNaN(Date.parse(arg))) throw new Error(`--date requires a valid date (got '${arg}')`)
3940
aroundDate = new Date(arg)
40-
} else
41+
} else if (option === '--repository') repository = getArg()
42+
else
4143
throw new Error(`Unhandled option: '${option}`)
4244
}
4345

@@ -48,6 +50,16 @@
4850
process.env.GITHUB_APP_ID = localSettings.Values.GITHUB_APP_ID
4951
process.env.GITHUB_APP_PRIVATE_KEY = localSettings.Values.GITHUB_APP_PRIVATE_KEY
5052

53+
const repositoryID = !repository ? false : await (async () => {
54+
const [owner, repo] = repository.split('/')
55+
const getInstallationIdForRepo = require('./GitForWindowsHelper/get-installation-id-for-repo')
56+
const installationId = await getInstallationIdForRepo(console, owner, repo)
57+
const getInstallationAccessToken = require('./GitForWindowsHelper/get-installation-access-token')
58+
const token = await getInstallationAccessToken(console, installationId)
59+
const gitHubRequest = require('./GitForWindowsHelper/github-api-request')
60+
return (await gitHubRequest(console, token, 'GET', `/repos/${repository}`)).id
61+
})()
62+
5163
const gitHubRequestAsApp = require('./GitForWindowsHelper/github-api-request-as-app')
5264

5365
const getAtCursor = async cursor => {
@@ -61,6 +73,7 @@
6173
if (eventType && e.event !== eventType) return false
6274
if (since && e.epoch < since) return false
6375
if (until && e.epoch > until) return false
76+
if (repositoryID && e.repository_id !== repositoryID) return false
6477
return true
6578
})
6679
const newest = answer.shift()

0 commit comments

Comments
 (0)