Skip to content

get-webhook-event-payload: allow filtering by repository #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion get-webhook-event-payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

let eventType = undefined
let aroundDate = undefined
let repository = undefined

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

Expand All @@ -48,6 +50,16 @@
process.env.GITHUB_APP_ID = localSettings.Values.GITHUB_APP_ID
process.env.GITHUB_APP_PRIVATE_KEY = localSettings.Values.GITHUB_APP_PRIVATE_KEY

const repositoryID = !repository ? false : await (async () => {
const [owner, repo] = repository.split('/')
const getInstallationIdForRepo = require('./GitForWindowsHelper/get-installation-id-for-repo')
const installationId = await getInstallationIdForRepo(console, owner, repo)
const getInstallationAccessToken = require('./GitForWindowsHelper/get-installation-access-token')
const token = await getInstallationAccessToken(console, installationId)
const gitHubRequest = require('./GitForWindowsHelper/github-api-request')
return (await gitHubRequest(console, token, 'GET', `/repos/${repository}`)).id
})()

const gitHubRequestAsApp = require('./GitForWindowsHelper/github-api-request-as-app')

const getAtCursor = async cursor => {
Expand All @@ -61,6 +73,7 @@
if (eventType && e.event !== eventType) return false
if (since && e.epoch < since) return false
if (until && e.epoch > until) return false
if (repositoryID && e.repository_id !== repositoryID) return false
return true
})
const newest = answer.shift()
Expand Down