Skip to content

Add href and sha, make pullRequesetId optional #19

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 7 commits into from
Jul 17, 2023
Merged
Changes from 3 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
22 changes: 17 additions & 5 deletions automagicallyexecute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
debug,
getVariable,
setResult,
warning,
getEndpointAuthorizationParameter
} from 'azure-pipelines-task-lib'
import fetch from 'node-fetch'
Expand All @@ -28,6 +29,16 @@ const run = async (): Promise<void> => {
return
}

const sha = getVariable('Build.SourceVersion')
if (!sha) {
setResult(TaskResult.Failed, 'sha is required')
}

const ref = getVariable('Build.SourceBranch')
if (!ref) {
setResult(TaskResult.Failed, 'ref is required')
}

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

Expand All @@ -37,15 +48,16 @@ const run = async (): Promise<void> => {
: undefined,
project: getVariable('System.TeamProject'),
repositoryId: getVariable('Build.Repository.ID'),
pullRequestId: getVariable('System.PullRequest.PullRequestId')
pullRequestId: getVariable('System.PullRequest.PullRequestId'),
sha,
ref
}

if (!context.pullRequestId) {
setResult(
TaskResult.Failed,
warning(
'System.PullRequest.PullRequestId variable not available. ' +
'Make sure you run this task in a PR build validation pipeline, ' +
'otherwise we cannot comment back the test results'
'Make sure you run this task in a PR build validation pipeline ' +
'if you expect a comment with the test results on your PR'
)
}

Expand Down