From 0213d1aa9676916249c465a6683ce3ee590b8bb7 Mon Sep 17 00:00:00 2001 From: Gyan Prakash Kumar Date: Fri, 29 Mar 2019 14:15:39 +0530 Subject: [PATCH 1/2] Handle version input from artifact --- .../resources.resjson/en-US/resources.resjson | 2 +- Tasks/DownloadGitHubReleaseV0/main.ts | 21 ++++++++----------- Tasks/DownloadGitHubReleaseV0/task.json | 4 ++-- Tasks/DownloadGitHubReleaseV0/task.loc.json | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson index 62e7b44d4c80..0672e2d588a2 100644 --- a/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson @@ -7,7 +7,7 @@ "loc.input.help.connection": "GitHub service connection", "loc.input.label.userRepository": "Repository", "loc.input.help.userRepository": "GitHub repository full name", - "loc.input.label.defaultVersionType": "Default release version type", + "loc.input.label.defaultVersionType": "Default version", "loc.input.help.defaultVersionType": "Download assets from latest release or specific release version/tag", "loc.input.label.version": "Release", "loc.input.help.version": "Release version/tag to download", diff --git a/Tasks/DownloadGitHubReleaseV0/main.ts b/Tasks/DownloadGitHubReleaseV0/main.ts index 5c5818d75bf9..db3862f3676e 100644 --- a/Tasks/DownloadGitHubReleaseV0/main.ts +++ b/Tasks/DownloadGitHubReleaseV0/main.ts @@ -159,20 +159,17 @@ async function main(): Promise { } } - if (!!defaultVersionType) { - switch (defaultVersionType.toLowerCase()) { - case 'latest': release = await executeWithRetries("getLatestRelease", () => getLatestRelease(repositoryName, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); - break; - case 'specifictag': release = await executeWithRetries("getTaggedRelease", () => getTaggedRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); - break; - case 'specificversion': release = await executeWithRetries("getSpecificRelease", () => getSpecificRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); - break; - default: release = null; - } - } else { + if (!!defaultVersionType && defaultVersionType.toLowerCase() == 'specificversion') { + release = await executeWithRetries("getSpecificRelease", () => getSpecificRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); + } + else if (!!defaultVersionType && defaultVersionType.toLowerCase() == 'specifictag') { + release = await executeWithRetries("getTaggedRelease", () => getTaggedRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); + } + else if (!defaultVersionType || defaultVersionType.toLowerCase() == 'latest') { if (!!version) { release = await executeWithRetries("getTaggedRelease", () => getTaggedRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); - } else { + } + else { release = await executeWithRetries("getLatestRelease", () => getLatestRelease(repositoryName, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); } } diff --git a/Tasks/DownloadGitHubReleaseV0/task.json b/Tasks/DownloadGitHubReleaseV0/task.json index 5f329cb4f8f3..25f1604e0bc6 100644 --- a/Tasks/DownloadGitHubReleaseV0/task.json +++ b/Tasks/DownloadGitHubReleaseV0/task.json @@ -11,7 +11,7 @@ "version": { "Major": 0, "Minor": 149, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "1.99.0", "instanceNameFormat": "Download GitHub Release", @@ -40,7 +40,7 @@ { "name": "defaultVersionType", "type": "pickList", - "label": "Default release version type", + "label": "Default version", "defaultValue": "latest", "required": true, "options": { diff --git a/Tasks/DownloadGitHubReleaseV0/task.loc.json b/Tasks/DownloadGitHubReleaseV0/task.loc.json index b748758958ef..5a778f2890b9 100644 --- a/Tasks/DownloadGitHubReleaseV0/task.loc.json +++ b/Tasks/DownloadGitHubReleaseV0/task.loc.json @@ -11,7 +11,7 @@ "version": { "Major": 0, "Minor": 149, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "1.99.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", From 419dc289172005439c07fcd0c564e969f31cdff3 Mon Sep 17 00:00:00 2001 From: Gyan Prakash Kumar Date: Fri, 29 Mar 2019 16:05:13 +0530 Subject: [PATCH 2/2] resolve comments --- .../resources.resjson/en-US/resources.resjson | 3 +-- Tasks/DownloadGitHubReleaseV0/main.ts | 17 ++++++++--------- Tasks/DownloadGitHubReleaseV0/task.json | 3 +-- Tasks/DownloadGitHubReleaseV0/task.loc.json | 3 +-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson index 0672e2d588a2..d7c217680954 100644 --- a/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DownloadGitHubReleaseV0/Strings/resources.resjson/en-US/resources.resjson @@ -17,6 +17,5 @@ "loc.input.help.downloadPath": "Path on the agent machine where the release assets will be downloaded", "loc.messages.DownloadArtifacts": "Downloading assets of release '%s' from: %s", "loc.messages.ArtifactsSuccessfullyDownloaded": "Successfully downloaded release assets to '%s'", - "loc.messages.InvalidRelease": "The release Id/Tag input '%s' is not valid", - "loc.messages.InvalidDefaultVersionType": "The DefaultVersionType input '%s' is not valid" + "loc.messages.InvalidRelease": "The release version/tag input '%s' is not valid" } \ No newline at end of file diff --git a/Tasks/DownloadGitHubReleaseV0/main.ts b/Tasks/DownloadGitHubReleaseV0/main.ts index db3862f3676e..78ee4079c373 100644 --- a/Tasks/DownloadGitHubReleaseV0/main.ts +++ b/Tasks/DownloadGitHubReleaseV0/main.ts @@ -133,6 +133,10 @@ async function main(): Promise { let version = tl.getInput("version", false); let release: Release = null; + if (!defaultVersionType) { + defaultVersionType = "latest"; + } + var token = tl.getEndpointAuthorizationParameter(connection, 'AccessToken', false); var retryLimit = parseInt(tl.getVariable("VSTS_HTTP_RETRY")) ? parseInt(tl.getVariable("VSTS_HTTP_RETRY")) : defaultRetryLimit; @@ -159,13 +163,13 @@ async function main(): Promise { } } - if (!!defaultVersionType && defaultVersionType.toLowerCase() == 'specificversion') { + if (defaultVersionType.toLowerCase() == 'specificversion') { release = await executeWithRetries("getSpecificRelease", () => getSpecificRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); } - else if (!!defaultVersionType && defaultVersionType.toLowerCase() == 'specifictag') { + else if (defaultVersionType.toLowerCase() == 'specifictag') { release = await executeWithRetries("getTaggedRelease", () => getTaggedRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); } - else if (!defaultVersionType || defaultVersionType.toLowerCase() == 'latest') { + else { if (!!version) { release = await executeWithRetries("getTaggedRelease", () => getTaggedRelease(repositoryName, version, customCredentialHandler), retryLimit).catch((reason) => { reject(reason); }); } @@ -174,12 +178,7 @@ async function main(): Promise { } } - if (!release) { - reject(tl.loc("InvalidDefaultVersionType", defaultVersionType)); - return; - } - - if (!release.Id) { + if (!release || !release.Id) { reject(tl.loc("InvalidRelease", version)); return; } diff --git a/Tasks/DownloadGitHubReleaseV0/task.json b/Tasks/DownloadGitHubReleaseV0/task.json index 25f1604e0bc6..887d47ed6436 100644 --- a/Tasks/DownloadGitHubReleaseV0/task.json +++ b/Tasks/DownloadGitHubReleaseV0/task.json @@ -116,7 +116,6 @@ "messages": { "DownloadArtifacts": "Downloading assets of release '%s' from: %s", "ArtifactsSuccessfullyDownloaded": "Successfully downloaded release assets to '%s'", - "InvalidRelease": "The release Id/Tag input '%s' is not valid", - "InvalidDefaultVersionType": "The DefaultVersionType input '%s' is not valid" + "InvalidRelease": "The release version/tag input '%s' is not valid" } } diff --git a/Tasks/DownloadGitHubReleaseV0/task.loc.json b/Tasks/DownloadGitHubReleaseV0/task.loc.json index 5a778f2890b9..b6ff516f1306 100644 --- a/Tasks/DownloadGitHubReleaseV0/task.loc.json +++ b/Tasks/DownloadGitHubReleaseV0/task.loc.json @@ -116,7 +116,6 @@ "messages": { "DownloadArtifacts": "ms-resource:loc.messages.DownloadArtifacts", "ArtifactsSuccessfullyDownloaded": "ms-resource:loc.messages.ArtifactsSuccessfullyDownloaded", - "InvalidRelease": "ms-resource:loc.messages.InvalidRelease", - "InvalidDefaultVersionType": "ms-resource:loc.messages.InvalidDefaultVersionType" + "InvalidRelease": "ms-resource:loc.messages.InvalidRelease" } } \ No newline at end of file