Skip to content

make automagically url configurable #4

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
May 16, 2023
Merged
Show file tree
Hide file tree
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
41 changes: 25 additions & 16 deletions automagicallyexecute/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {
TaskResult,
getInputRequired,
getInput,
debug,
getVariable,
setResult,
getEndpointAuthorizationParameter
} from 'azure-pipelines-task-lib'
import fetch from 'node-fetch'

const AUTOMAGICALLY_BASE_URL = 'https://automagically-5vr3ysri3a-ey.a.run.app/'
const urlDefault = 'https://automagically-5vr3ysri3a-ey.a.run.app/'
const urlOverride = getInput('automagicallyUrl', false) ?? ''
const automagicallyUrl = urlOverride.length === 0 ? urlDefault : urlOverride
const executeUrl = `${automagicallyUrl}/api/v1/execute`

const run = async (): Promise<void> => {
try {
Expand All @@ -23,23 +28,28 @@ const run = async (): Promise<void> => {
return
}

// https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables
const collectionUri = getVariable('System.TeamFoundationCollectionUri')

const context = {
organization: collectionUri
? new URL(collectionUri).pathname.split('/').at(1)
: undefined,
project: getVariable('System.TeamProject'),
repositoryId: getVariable('Build.Repository.ID'),
pullRequestId: getVariable('System.PullRequest.PullRequestId')
}

debug(JSON.stringify({executeUrl, context}, null, 2))

// https://github.com/microsoft/azure-pipelines-task-lib/issues/579
const accessToken = getEndpointAuthorizationParameter(
'SystemVssConnection',
'AccessToken',
false
)

// https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables
const collectionUri = getVariable('System.TeamFoundationCollectionUri')
const organization = collectionUri
? new URL(collectionUri).pathname.split('/').at(1)
: undefined
const project = getVariable('System.TeamProject')
const repositoryId = getVariable('Build.Repository.ID')
const pullRequestId = getVariable('System.PullRequest.PullRequestId')

const response = await fetch(`${AUTOMAGICALLY_BASE_URL}/api/v1/execute`, {
const response = await fetch(executeUrl, {
headers: {
'Content-Type': 'application/json'
},
Expand All @@ -49,10 +59,7 @@ const run = async (): Promise<void> => {
context: {
source: 'azureDevOps',
accessToken,
organization,
project,
repositoryId,
pullRequestId
...context
}
}),
method: 'POST'
Expand All @@ -61,7 +68,9 @@ const run = async (): Promise<void> => {
if (!response.ok) {
// noinspection ExceptionCaughtLocallyJS
throw new Error(
`response not ok ${response.status}, body: ${await response.json()}`
`response not ok ${response.status}, body: ${JSON.stringify({
body: await response.json()
})}`
)
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion automagicallyexecute/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 0
"Patch": 1
},
"instanceNameFormat": "Execute Automagically",
"inputs": [
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "automagically-execute-task",
"name": "octomind automagically execute",
"version": "1.1.0",
"version": "1.1.1",
"publisher": "octomind",
"targets": [
{
Expand Down