diff --git a/GitForWindowsHelper/azure-pipelines.js b/GitForWindowsHelper/azure-pipelines.js deleted file mode 100644 index a3e184c..0000000 --- a/GitForWindowsHelper/azure-pipelines.js +++ /dev/null @@ -1,187 +0,0 @@ -const triggerAzurePipeline = async (context, token, organization, project, buildDefinitionId, sourceBranch, parameters) => { - const auth = Buffer.from('PAT:' + token).toString('base64') - const headers = { - 'Accept': 'application/json; api-version=5.0-preview.5; excludeUrls=true', - 'Authorization': 'Basic ' + auth, - } - const body = { - 'definition': { 'id': buildDefinitionId }, - 'sourceBranch': sourceBranch, - 'parameters': JSON.stringify(parameters), - } - - const { httpsRequest } = require('./https-request') - return await httpsRequest( - context, - 'dev.azure.com', - 'POST', - `/${organization}/${project}/_apis/build/builds?ignoreWarnings=false&api-version=5.0-preview.5`, - body, - headers - ) -} - -const triggerGitArtifacts = async (context, prNumber) => { - const githubApiRequest = require('./github-api-request') - const answer = await githubApiRequest( - context, - null, - 'GET', - `/repos/git-for-windows/git/pulls/${prNumber}` - ) - const sourceBranch = `refs/pull/${prNumber}/head` - const useBranch = `${answer.head.ref}@https://github.com/${answer.head.repo.full_name}` - const parameters = { - "use.branch": useBranch - } - const token = process.env['AZURE_PIPELINE_TRIGGER_TOKEN'] - const answer2 = await triggerAzurePipeline(context, token, 'git-for-windows', 'git', 34, sourceBranch, parameters) - return { - id: answer2.id, - url: answer2._links.web.href - } -} - -const listReleases = async (context, token, organization, project) => { - const auth = Buffer.from('PAT:' + token).toString('base64') - const headers = { - 'Accept': 'application/json; api-version=7.0; excludeUrls=true', - 'Authorization': 'Basic ' + auth, - } - - const { httpsRequest } = require('./https-request') - return await httpsRequest( - context, - 'vsrm.dev.azure.com', - 'GET', - `/${organization}/${project}/_apis/release/releases`, - undefined, - headers - ) -} - -const getRelease = async (context, token, organization, project, releaseId) => { - const auth = Buffer.from('PAT:' + token).toString('base64') - const headers = { - 'Accept': 'application/json; api-version=7.0; excludeUrls=true', - 'Authorization': 'Basic ' + auth, - } - - const { httpsRequest } = require('./https-request') - return await httpsRequest( - context, - 'vsrm.dev.azure.com', - 'GET', - `/${organization}/${project}/_apis/release/releases/${releaseId}`, - undefined, - headers - ) -} - -const createRelease = async ( - context, - token, - organization, - project, - releaseDefinitionId, - artifactAlias, - artifactBuildRunId, - artifactBuildRunName, - artifactBuildDefinitionId, - artifactBuildDefinitionName, - sourceBranch, - sourceCommitId, - repo -) => { - const auth = Buffer.from("PAT:" + token).toString("base64"); - const headers = { - Accept: "application/json; api-version=7.0; excludeUrls=true", - Authorization: "Basic " + auth, - }; - const body = { - definitionId: releaseDefinitionId, - isDraft: false, - description: "", - artifacts: [ - { - alias: artifactAlias, - instanceReference: { - id: artifactBuildRunId, - name: artifactBuildRunName, - definitionId: artifactBuildDefinitionId, - definitionName: artifactBuildDefinitionName, - sourceBranch, - sourceVersion: sourceCommitId, - sourceRepositoryId: repo, - sourceRepositoryType: "GitHub", - }, - }, - ], - properties: { ReleaseCreationSource: "GitForWindowsHelper" }, - } - - const { httpsRequest } = require('./https-request') - return await httpsRequest( - context, - 'vsrm.dev.azure.com', - 'POST', - `/${organization}/${project}/_apis/release/releases`, - body, - headers - ) -} - -const releaseGitArtifacts = async (context, prNumber) => { - const githubApiRequest = require('./github-api-request') - const answer = await githubApiRequest( - context, - null, - 'GET', - `/repos/git-for-windows/git/pulls/${prNumber}` - ) - - const sourceBranch = `refs/pull/${prNumber}/head` - const sourceCommitId = answer.head.sha - - const { check_runs } = await githubApiRequest( - context, - null, - 'GET', - `/repos/git-for-windows/git/commits/${sourceCommitId}/check-runs` - ) - const artifactBuildDefinitionName = 'Git artifacts' - const gitArtifactsRun = check_runs.filter(e => e.name === artifactBuildDefinitionName) - if (gitArtifactsRun.length !== 1) throw new Error(`Expected one run, got ${JSON.stringify(gitArtifactsRun, null, 2)}`) - const [artifactBuildDefinitionId, artifactBuildRunId] = gitArtifactsRun[0].external_id.split('|') - const [artifactBuildRunName] = gitArtifactsRun[0].output.title.match(/v\d+(?:\.\d+)*\.windows\.\d+/) - - const token = process.env['AZURE_PIPELINE_TRIGGER_TOKEN'] - const answer2 = await createRelease( - context, - token, - 'git-for-windows', - 'git', - 1, - 'artifacts', - artifactBuildRunId, - artifactBuildRunName, - artifactBuildDefinitionId, - artifactBuildDefinitionName, - sourceBranch, - sourceCommitId, - 'git-for-windows/git' - ) - return { - id: answer2.id, - url: answer2._links.web.href - } -} - -module.exports = { - triggerAzurePipeline, - triggerGitArtifacts, - listReleases, - getRelease, - createRelease, - releaseGitArtifacts -} \ No newline at end of file diff --git a/GitForWindowsHelper/trigger-workflow-dispatch.js b/GitForWindowsHelper/trigger-workflow-dispatch.js index eba07bb..37cab66 100644 --- a/GitForWindowsHelper/trigger-workflow-dispatch.js +++ b/GitForWindowsHelper/trigger-workflow-dispatch.js @@ -36,6 +36,9 @@ const waitForWorkflowRun = async (context, owner, repo, workflow_id, after, toke } const triggerWorkflowDispatch = async (context, token, owner, repo, workflow_id, ref, inputs) => { + if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) { + throw new Error(`Would have triggered workflow ${workflow_id} on ${owner}/${repo} with ref ${ref} and inputs ${JSON.stringify(inputs)}`) + } const { headers: { date } } = await githubApiRequest( context, token, diff --git a/README.md b/README.md index 7e356cd..c24251c 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,13 @@ For convenience, the command can be abbreviated as `/add relnote ", "AzureWebJobsStorage": "", "GITHUB_APP_ID": "", "GITHUB_APP_CLIENT_ID": "", @@ -128,7 +127,7 @@ After the deployment succeeded, in the "Overview" tab, there is a "Get publish p A few environment variables will have to be configured for use with the Azure Function. This can be done on the "Configuration" tab, which is in the "Settings" group. -Concretely, the environment variables `AZURE_PIPELINE_TRIGGER_TOKEN`, `GITHUB_WEBHOOK_SECRET`, `GITHUB_APP_PRIVATE_KEY`, `GITHUB_APP_CLIENT_SECRET`, `GITHUB_APP_CLIENT_ID` and `GITHUB_APP_ID` need to be set. For the first, a generated random string was used. The private key, client secret and ID of the GitHub App are not known at this time, though, therefore they will have to be set in the Azure Function Configuration later. +Concretely, the environment variables `GITHUB_WEBHOOK_SECRET`, `GITHUB_APP_PRIVATE_KEY`, `GITHUB_APP_CLIENT_SECRET`, `GITHUB_APP_CLIENT_ID` and `GITHUB_APP_ID` need to be set. For the first, a generated random string was used. The private key, client secret and ID of the GitHub App are not known at this time, though, therefore they will have to be set in the Azure Function Configuration later. ### The repository diff --git a/test-pr-comment-delivery.js b/test-pr-comment-delivery.js index c9e53d3..0f4fa5a 100755 --- a/test-pr-comment-delivery.js +++ b/test-pr-comment-delivery.js @@ -69,7 +69,7 @@ // avoid accidentally triggering anything delete process.env.GITHUB_APP_PRIVATE_KEY - delete process.env.AZURE_PIPELINE_TRIGGER_TOKEN + process.env.DO_NOT_TRIGGER_ANYTHING = 'true' const index = require('./GitForWindowsHelper/index') console.log(await index(context, req) || context.res)