Skip to content

Commit

Permalink
Merge pull request #134 from coloursofnoise/main
Browse files Browse the repository at this point in the history
Allow user-specified reasonFilter for retrieving builds
  • Loading branch information
dscho authored Oct 2, 2021
2 parents bb6fc7f + b166a57 commit 52da120
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Every Azure Pipeline has a numerical identifier that is part of the URL. For exa

Pipelines can have an arbitrary number of artifacts, which are identified by a name. The `artifact` parameter specifies which one to download. It can be omitted if the given Pipeline run has only one artifact attached to it.

### Build filters

The `reasonFilter` parameter can be added to filter by the reason for a build.
A list of accepted reasons can be found [here](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0#buildreason). This parameter defaults to `all` if omitted.

### Strip prefix

Pipeline artifacts can contain entire directory structures. The `stripPrefix` parameter allows filtering by a given path prefix; Any files matching that prefix will be written (after stripping the prefix), all other files will be skipped.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
required: false
description: 'Use @actions/cache to accelerate this Action'
default: 'true'
reasonFilter:
required: false
description: 'Filter results by the reason for the build; Defaults to "all"'
default: 'all'
runs:
using: 'node12'
main: 'dist/index.js'
6 changes: 3 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ async function run(): Promise<void> {
core.getInput('repository'),
core.getInput('definitionId'),
core.getInput('artifact'),
core.getInput('stripPrefix')
core.getInput('stripPrefix'),
core.getInput('reasonFilter')
)
const outputDirectory = core.getInput('path') || artifactName
let useCache = core.getInput('cache') === 'true'
Expand Down
5 changes: 3 additions & 2 deletions src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export async function get(
repository: string,
definitionId: string,
artifactName: string,
stripPrefix?: string
stripPrefix?: string,
reasonFilter = 'all'
): Promise<{
artifactName: string
stripPrefix: string
Expand All @@ -137,7 +138,7 @@ export async function get(
count: number
value: [{id: string; downloadURL: string}]
}>(
`${baseURL}?definitions=${definitionId}&statusFilter=completed&resultFilter=succeeded&$top=1`
`${baseURL}?definitions=${definitionId}&statusFilter=completed&resultFilter=succeeded&reasonFilter=${reasonFilter}&$top=1`
)
if (data.count !== 1) {
throw new Error(`Unexpected number of builds: ${data.count}`)
Expand Down

0 comments on commit 52da120

Please sign in to comment.