From 6c97a5060d2bd8838083166629893aabdafd743f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:01:07 +0200 Subject: [PATCH 1/9] vscode(Debug Tests): show the output in the integrated console Otherwise it's a bit tricky to see what is happening... Signed-off-by: Johannes Schindelin --- .vscode/launch.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index b8d595bd..65d3c52e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ { "type": "node", "request": "launch", + "console": "integratedTerminal", "name": "Debug Tests", "program": "${workspaceRoot}/node_modules/.bin/jest", "cwd": "${workspaceRoot}", From 1665a879bf31b26c8926630163ca4bea8c4320d1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 21 Aug 2025 10:49:33 +0200 Subject: [PATCH 2/9] test: stop asserting things _inside_ a mocked function It is bad practice, and for good reason: It makes it hard to verify things when the same, mocked function is called _multiple_ times inside the same test case, and with different parameters that need to be verified, too. Signed-off-by: Johannes Schindelin --- __tests__/index.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 31e3059f..74937679 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -1,9 +1,5 @@ -const mockTriggerWorkflowDispatch = jest.fn(async (_context, _token, owner, repo, workflow_id, ref, inputs) => { - expect(`${owner}/${repo}`).toEqual('gitgitgadget-workflows/gitgitgadget-workflows') - expect(workflow_id).toEqual('sync-ref.yml') - expect(ref).toEqual('main') - expect(inputs).toEqual({ ref: 'refs/heads/next' }) - return { html_url: ''} +const mockTriggerWorkflowDispatch = jest.fn(async (_context, _token, _owner, _repo, workflow_id, ref, inputs) => { + return { html_url: `` } }) jest.mock('../GitGitGadget/trigger-workflow-dispatch', () => ({ triggerWorkflowDispatch: mockTriggerWorkflowDispatch @@ -197,7 +193,7 @@ testWebhookPayload('react to `next` being pushed to git/git', 'push', { } }, (context) => { expect(context.res).toEqual({ - body: 'push(refs/heads/next): triggered ' + body: 'push(refs/heads/next): triggered ' }) expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1) expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([ From 5aebcfdedb2ddd4568b1b698bcf32edde3de5037 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 12:52:25 +0200 Subject: [PATCH 3/9] Add a function to list GitHub workflow runs This function will be used to determine whether a workflow run is already queued, to prevent concurrent runs of the upcoming GitHub workflows that replace GitGitGadget's Azure Pipelines. Signed-off-by: Johannes Schindelin --- GitGitGadget/trigger-workflow-dispatch.js | 29 ++++++++++++++++++++- __tests__/trigger-workflow-dispatch.test.js | 16 +++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/GitGitGadget/trigger-workflow-dispatch.js b/GitGitGadget/trigger-workflow-dispatch.js index 1ee8f132..fd2ba7fd 100644 --- a/GitGitGadget/trigger-workflow-dispatch.js +++ b/GitGitGadget/trigger-workflow-dispatch.js @@ -56,7 +56,34 @@ const triggerWorkflowDispatch = async (context, token, owner, repo, workflow_id, return runs[0] } +const listWorkflowRuns = async (context, token, owner, repo, workflow_id, branch, status) => { + if (token === undefined) { + const { getInstallationIdForRepo } = require('./get-installation-id-for-repo') + const installationID = await getInstallationIdForRepo(context, owner, repo) + + const { getInstallationAccessToken } = require('./get-installation-access-token') + token = await getInstallationAccessToken(context, installationID) + } + + const query = [ + branch && `branch=${branch}`, + status && `status=${status}`, + ] + .filter((e) => e) + .map((e, i) => `${i === 0 ? '?' : '&'}${e}`) + .join('') + + const result = await gitHubAPIRequest( + context, + token, + 'GET', + `/repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs${query}`, + ) + return result.workflow_runs +} + module.exports = { triggerWorkflowDispatch, - waitForWorkflowRun + waitForWorkflowRun, + listWorkflowRuns, } diff --git a/__tests__/trigger-workflow-dispatch.test.js b/__tests__/trigger-workflow-dispatch.test.js index 36c7ebe5..64e02211 100644 --- a/__tests__/trigger-workflow-dispatch.test.js +++ b/__tests__/trigger-workflow-dispatch.test.js @@ -16,11 +16,19 @@ const mockHTTPSRequest = jest.fn(async (_context, _hostname, method, requestPath ] } } + if (method === 'GET' && requestPath === '/repos/hello/world/actions/workflows/the-workflow.yml/runs?branch=main&status=queued') { + return { + workflow_runs: [ + { id: 1, head_branch: 'main', status: 'queued' }, + { id: 2, head_branch: 'main', status: 'queued' }, + ] + } + } throw new Error(`Unexpected requestPath: ${method} '${requestPath}'`) }) jest.mock('../GitGitGadget/https-request', () => { return { httpsRequest: mockHTTPSRequest } }) -const { triggerWorkflowDispatch } = require('../GitGitGadget/trigger-workflow-dispatch') +const { triggerWorkflowDispatch, listWorkflowRuns } = require('../GitGitGadget/trigger-workflow-dispatch') const { generateKeyPairSync } = require('crypto') @@ -44,4 +52,10 @@ test('trigger a workflow_dispatch event and wait for workflow run', async () => path: '.github/workflows/the-workflow.yml', breadcrumb: true }) +}) + +test('list workflow runs', async () => { + const context = {} + const runs = await listWorkflowRuns(context, 'my-token', 'hello', 'world', 'the-workflow.yml', 'main', 'queued') + expect(runs.length).toEqual(2) }) \ No newline at end of file From 31edbe50e8f3e2c9d12e23c3f10b6e8840273374 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:16:03 +0200 Subject: [PATCH 4/9] Simplify the `triggerWorkflowDispatch()` call This is easier to read, and it will make similar calls that I am about to introduce also easier to read. Signed-off-by: Johannes Schindelin --- GitGitGadget/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index d5cff660..6e74c488 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -44,6 +44,7 @@ module.exports = async (context, req) => { 'git': 13, 'gitgitgadget': 3, }; + const a = [context, undefined, 'gitgitgadget-workflows', 'gitgitgadget-workflows'] const eventType = context.req.headers['x-github-event']; context.log(`Got eventType: ${eventType}`); @@ -62,10 +63,7 @@ module.exports = async (context, req) => { context.res = { body: `Ignoring pushes to ${req.body.repository.full_name}` } } else { const run = await triggerWorkflowDispatch( - context, - undefined, - 'gitgitgadget-workflows', - 'gitgitgadget-workflows', + ...a, 'sync-ref.yml', 'main', { ref: req.body.ref From 8580d331512cf96da840c921a371b06f53337811 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:17:39 +0200 Subject: [PATCH 5/9] Trigger `update-prs` and `update-mail-to-commit-notes` on `seen` updates This is part of my ongoing effort to replace GitGitGadget's Azure Pipelines by GitHub workflows. Currently, the Azure Pipelines have the upstream Git repository as "source" (even if they don't check that out), i.e. Azure Pipelines poll for changes. In GitHub workflows, such a thing is no longer possible: There is no way to trigger a GitHub workflow on updates in _another_ repository than the workflow definition resides (a rather vexing limitation of GitHub Actions' architecture, to be sure). In this instance, we can avoid resorting to the ugly, ugly, yet all-too-common workaround of polling (which we do in `sync-git-mailing-list-mirror`) but can at least react to the respective webhook event (at least we _can_, what with the `gitgitgadget-git` app being installed on `git/git`). Signed-off-by: Johannes Schindelin --- GitGitGadget/index.js | 13 +++++++++-- __tests__/index.test.js | 51 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index 6e74c488..9699204a 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -12,7 +12,7 @@ const { validateGitHubWebHook } = require('./validate-github-webhook'); const { triggerAzurePipeline } = require('./trigger-azure-pipeline'); -const { triggerWorkflowDispatch } = require('./trigger-workflow-dispatch') +const { triggerWorkflowDispatch, listWorkflowRuns } = require('./trigger-workflow-dispatch') module.exports = async (context, req) => { try { @@ -69,7 +69,16 @@ module.exports = async (context, req) => { ref: req.body.ref } ) - context.res = { body: `push(${req.body.ref}): triggered ${run.html_url}` } + const extra = [] + if (req.body.ref === 'refs/heads/seen') { + for (const workflow of ['update-prs.yml', 'update-mail-to-commit-notes.yml']) { + if ((await listWorkflowRuns(...a, workflow, 'main', 'queued')).length === 0) { + const run = await triggerWorkflowDispatch(...a, workflow, 'main') + extra.push(` and ${run.html_url}`) + } + } + } + context.res = { body: `push(${req.body.ref}): triggered ${run.html_url}${extra.join('')}` } } } else if (eventType === 'issue_comment') { const triggerToken = process.env['GITGITGADGET_TRIGGER_TOKEN']; diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 74937679..a06f88b5 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -2,7 +2,17 @@ const mockTriggerWorkflowDispatch = jest.fn(async (_context, _token, _owner, _re return { html_url: `` } }) jest.mock('../GitGitGadget/trigger-workflow-dispatch', () => ({ - triggerWorkflowDispatch: mockTriggerWorkflowDispatch + triggerWorkflowDispatch: mockTriggerWorkflowDispatch, + listWorkflowRuns: jest.fn(async (_context, _token, _owner, _repo, workflow_id, branch, status) => { + if (workflow_id === 'update-prs.yml' && branch === 'main' && status === 'queued') { + // pretend that `update-prs` is clogged up, for whatever reason + return [ + { id: 1, head_branch: 'main', status: 'queued', html_url: '' }, + { id: 2, head_branch: 'main', status: 'queued', html_url: '' } + ] + } + return [] + }) })) const index = require('../GitGitGadget/index') @@ -206,4 +216,43 @@ testWebhookPayload('react to `next` being pushed to git/git', 'push', { ref: 'refs/heads/next' } ]) +}) + +testWebhookPayload('react to `seen` being pushed to git/git', 'push', { + ref: 'refs/heads/seen', + repository: { + full_name: 'git/git', + owner: { + login: 'git' + } + } +}, (context) => { + expect(context.res).toEqual({ + body: [ + 'push(refs/heads/seen):', + 'triggered ', + 'and ' + ].join(' ') + }) + // we expect `update-prs` _not_ to be triggered here because we pretend that it is already queued + expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(2) + expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([ + context, + undefined, + 'gitgitgadget-workflows', + 'gitgitgadget-workflows', + 'sync-ref.yml', + 'main', { + ref: 'refs/heads/seen' + } + ]) + expect(mockTriggerWorkflowDispatch.mock.calls[1]).toEqual([ + context, + undefined, + 'gitgitgadget-workflows', + 'gitgitgadget-workflows', + 'update-mail-to-commit-notes.yml', + 'main', + undefined + ]) }) \ No newline at end of file From 2d7ebaed40cb8efa6e530a76960010d3de0619b6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:33:03 +0200 Subject: [PATCH 6/9] Trigger `handle-new-mails` on new mails GitGitGadget maintains a mirror of the Git mailing list at https://github.com/gitgitgadget/git-mailing-list-mirror/, synchronizing it via the `sync-git-mailing-list-mirror` workflow. As a side effect of having installed the `gitgitgadget` GitHub App on that repository (so that the workflow can push updates), GitGitGadget's App also receives webhook events from that repository. Let's put that fact to good use by triggering the new `handle-new-mails` GitHub workflow that wants to replace GitGitGadget's "Mirror Git List to GitGitGadget's PRs" Azure Pipeline at https://dev.azure.com/gitgitgadget/git/_build?definitionId=5 (which polled the upstream Git mailing list repository). Signed-off-by: Johannes Schindelin --- GitGitGadget/index.js | 16 +++++++++++++++- __tests__/index.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index 9699204a..e9b8ad5d 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -59,7 +59,21 @@ module.exports = async (context, req) => { body: `Ignored event type: ${eventType}`, }; } else if (eventType === 'push') { - if (req.body.repository.full_name !== 'git/git') { + if (req.body.repository.full_name ==='gitgitgadget/git-mailing-list-mirror') { + context.res = { body: `push(${req.body.ref} in ${req.body.repository.full_name}): ` } + if (req.body.ref === 'refs/heads/lore-1') { + const queued = await listWorkflowRuns(...a, 'handle-new-mails.yml', 'queued') + if (queued.length) { + context.res.body += [ + `skip triggering handle-new-emails, ${queued} already queued:`, + queued.map(e => `- ${e.html_url}`) + ].join('\n') + } else { + const run = await triggerWorkflowDispatch(...a, 'handle-new-mails.yml', 'main') + context.res.body += `triggered ${run.html_url}` + } + } else context.res.body += `Ignoring non-default branches` + } else if (req.body.repository.full_name !== 'git/git') { context.res = { body: `Ignoring pushes to ${req.body.repository.full_name}` } } else { const run = await triggerWorkflowDispatch( diff --git a/__tests__/index.test.js b/__tests__/index.test.js index a06f88b5..1eeade08 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -255,4 +255,31 @@ testWebhookPayload('react to `seen` being pushed to git/git', 'push', { 'main', undefined ]) +}) + +testWebhookPayload('react to `lore-1` being pushed to https://github.com/gitgitgadget/git-mailing-list-mirror', 'push', { + ref: 'refs/heads/lore-1', + repository: { + full_name: 'gitgitgadget/git-mailing-list-mirror', + owner: { + login: 'gitgitgadget' + } + } +}, (context) => { + expect(context.res).toEqual({ + body: [ + 'push(refs/heads/lore-1 in gitgitgadget/git-mailing-list-mirror):', + 'triggered ' + ].join(' ') + }) + expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1) + expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([ + context, + undefined, + 'gitgitgadget-workflows', + 'gitgitgadget-workflows', + 'handle-new-mails.yml', + 'main', + undefined + ]) }) \ No newline at end of file From ba6304006999116d4e8f0a8d49d48a7245ae2713 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:46:00 +0200 Subject: [PATCH 7/9] Trigger the new GitHub workflow to handle PR comments This _almost_ retires these Azure Pipelines: - GitGitGadget PR Handler https://dev.azure.com/gitgitgadget/git/_build?definitionId=3 - GitGitGadget PR Handler (git) https://dev.azure.com/gitgitgadget/git/_build?definitionId=13 - GitGitGadget PR Handler (dscho) https://dev.azure.com/gitgitgadget/git/_build?definitionId=12 The remaining responsibility of those Pipelines is to handle PR _pushes_, which I will address in the next commit. Signed-off-by: Johannes Schindelin --- GitGitGadget/index.js | 42 ++++++++++------------------------------- __tests__/index.test.js | 13 +++---------- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index e9b8ad5d..85a74232 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -10,8 +10,6 @@ */ const { validateGitHubWebHook } = require('./validate-github-webhook'); -const { triggerAzurePipeline } = require('./trigger-azure-pipeline'); - const { triggerWorkflowDispatch, listWorkflowRuns } = require('./trigger-workflow-dispatch') module.exports = async (context, req) => { @@ -29,27 +27,18 @@ module.exports = async (context, req) => { try { /* - * The Azure Pipeline needs to be installed as a PR build on _the very - * same_ repository that triggers this function. That is, when the - * Azure Function triggers GitGitGadget for gitgitgadget/git, it needs - * to know that pipelineId 3 is installed on gitgitgadget/git, and - * trigger that very pipeline. - * - * So whenever we extend GitGitGadget to handle another repository, we - * will have to add an Azure Pipeline, install it on that repository as - * a PR build, and add the information here. + * For various reasons, the GitGitGadget GitHub App can be installed + * on any random repository. However, GitGitGadget only wants to support + * the `gitgitgadget/git` and the `git/git` repository (with the + * `dscho/git` one thrown in for debugging purposes). */ - const pipelines = { - 'dscho': 12, - 'git': 13, - 'gitgitgadget': 3, - }; + const orgs = ['gitgitgadget', 'git', 'dscho'] const a = [context, undefined, 'gitgitgadget-workflows', 'gitgitgadget-workflows'] const eventType = context.req.headers['x-github-event']; context.log(`Got eventType: ${eventType}`); const repositoryOwner = req.body.repository.owner.login; - if (pipelines[repositoryOwner] === undefined) { + if (!orgs.includes(repositoryOwner)) { context.res = { status: 403, body: 'Refusing to work on a repository other than gitgitgadget/git or git/git' @@ -95,11 +84,6 @@ module.exports = async (context, req) => { context.res = { body: `push(${req.body.ref}): triggered ${run.html_url}${extra.join('')}` } } } else if (eventType === 'issue_comment') { - const triggerToken = process.env['GITGITGADGET_TRIGGER_TOKEN']; - if (!triggerToken) { - throw new Error('No configured trigger token'); - } - const comment = req.body.comment; const prNumber = req.body.issue.number; if (!comment || !comment.id || !prNumber) { @@ -121,19 +105,13 @@ module.exports = async (context, req) => { return; } - const sourceBranch = `refs/pull/${prNumber}/head`; - const parameters = { - 'pr.comment.id': comment.id, - }; - const pipelineId = pipelines[repositoryOwner]; - if (!pipelineId || pipelineId < 1) - throw new Error(`No pipeline set up for org ${repositoryOwner}`); - context.log(`Queuing with branch ${sourceBranch} and parameters ${JSON.stringify(parameters)}`); - await triggerAzurePipeline(triggerToken, 'gitgitgadget', 'git', pipelineId, sourceBranch, parameters); + const run = await triggerWorkflowDispatch(...a, 'handle-pr-comment.yml', 'main', { + 'pr-comment-url': comment.html_url + }) context.res = { // status: 200, /* Defaults to 200 */ - body: 'Okay!', + body: `Okay, triggered ${run.html_url}!`, }; } else { context.log(`Unhandled request:\n${JSON.stringify(req, null, 4)}`); diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 1eeade08..ce465ad3 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -153,17 +153,10 @@ const testIssueComment = (comment, repoOwner, fn) => { testIssueComment('/test', async (context) => { expect(context.done).toHaveBeenCalledTimes(1) expect(context.res).toEqual({ - body: 'Okay!' + body: 'Okay, triggered !' }) - expect(mockRequest.write).toHaveBeenCalledTimes(1) - expect(JSON.parse(mockRequest.write.mock.calls[0][0])).toEqual({ - definition: { - id: 3 - }, - sourceBranch: 'refs/pull/1886743660/head', - parameters: '{"pr.comment.id":27988538471837300}' - }) - expect(mockRequest.end).toHaveBeenCalledTimes(1) + expect(mockRequest.write).not.toHaveBeenCalled() + expect(mockRequest.end).not.toHaveBeenCalled() }) testIssueComment('/verify-repository', 'nope', (context) => { From d5eed8c7ccd1c450bf73f5a5f31664f4bcdea3ef Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Aug 2025 13:51:51 +0200 Subject: [PATCH 8/9] Trigger `handle-pr-push` on PR updates This is the final bit of the migration from GitGitGadget's Azure Pipelines to GitHub workflows. Signed-off-by: Johannes Schindelin --- GitGitGadget/index.js | 11 +++++++++++ __tests__/index.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index 85a74232..c26145e7 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -43,6 +43,17 @@ module.exports = async (context, req) => { status: 403, body: 'Refusing to work on a repository other than gitgitgadget/git or git/git' }; + } else if (eventType === 'pull_request') { + if (req.body.action !== 'opened' && req.body.action !== 'synchronize') { + context.res = { + body: `Ignoring pull request action: ${req.body.action}`, + }; + } else { + const run = await triggerWorkflowDispatch(...a, 'handle-pr-push.yml', 'main', { + 'pr-url': req.body.pull_request.html_url + }) + context.res = { body: `Okay, triggered ${run.html_url}!` }; + } } else if ((new Set(['check_run', 'status']).has(eventType))) { context.res = { body: `Ignored event type: ${eventType}`, diff --git a/__tests__/index.test.js b/__tests__/index.test.js index ce465ad3..7db164eb 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -275,4 +275,34 @@ testWebhookPayload('react to `lore-1` being pushed to https://github.com/gitgitg 'main', undefined ]) +}) +testWebhookPayload('react to PR push', 'pull_request', { + action: 'synchronize', + pull_request: { + html_url: 'https://github.com/gitgitgadget/git/pull/1956', + }, + repository: { + full_name: 'gitgitgadget/git', + owner: { + login: 'gitgitgadget' + } + } +}, (context) => { + expect(context.res).toEqual({ + body: [ + 'Okay, triggered !' + ].join(' ') + }) + expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1) + expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([ + context, + undefined, + 'gitgitgadget-workflows', + 'gitgitgadget-workflows', + 'handle-pr-push.yml', + 'main', { + 'pr-url': 'https://github.com/gitgitgadget/git/pull/1956', + } + ]) }) \ No newline at end of file From 3f63a6ac86abd67ca83146836919013567f691eb Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 21 Aug 2025 12:08:23 +0200 Subject: [PATCH 9/9] Retire the `triggerAzurePipeline()` function We no longer trigger any Azure Pipeline. Signed-off-by: Johannes Schindelin --- GitGitGadget/trigger-azure-pipeline.js | 48 -------------------------- 1 file changed, 48 deletions(-) delete mode 100644 GitGitGadget/trigger-azure-pipeline.js diff --git a/GitGitGadget/trigger-azure-pipeline.js b/GitGitGadget/trigger-azure-pipeline.js deleted file mode 100644 index 93eebfbe..00000000 --- a/GitGitGadget/trigger-azure-pipeline.js +++ /dev/null @@ -1,48 +0,0 @@ -const https = require('https'); - -const triggerAzurePipeline = async (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 json = JSON.stringify({ - 'definition': { 'id': buildDefinitionId }, - 'sourceBranch': sourceBranch, - 'parameters': JSON.stringify(parameters), - }); - headers['Content-Type'] = 'application/json'; - headers['Content-Length'] = Buffer.byteLength(json); - - const requestOptions = { - host: 'dev.azure.com', - port: '443', - path: `/${organization}/${project}/_apis/build/builds?ignoreWarnings=false&api-version=5.0-preview.5`, - method: 'POST', - headers: headers - }; - - return new Promise((resolve, reject) => { - const handleResponse = (res) => { - res.setEncoding('utf8'); - var response = ''; - res.on('data', (chunk) => { - response += chunk; - }); - res.on('end', () => { - resolve(JSON.parse(response)); - }); - res.on('error', (err) => { - reject(err); - }) - }; - - const request = https.request(requestOptions, handleResponse); - request.write(json); - request.end(); - }); -} - -module.exports = { - triggerAzurePipeline -} \ No newline at end of file