Skip to content

Commit

Permalink
Merge pull request #4 from Polymathian/fix-package-not-exist
Browse files Browse the repository at this point in the history
Handle Case where package does not yet exist
  • Loading branch information
Josh-Zhou authored Apr 8, 2024
2 parents cdca53d + dc41a93 commit 29b7fa0
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions versioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,37 @@ async function findOnCodeartifactByPrefix(domainName, format, packageName, repos

let nextToken = undefined;
do {
const listVersionsResp = await ca.listPackageVersions({
domain: domainName,
format: format,
package: packageName,
repository: repositoryName,
status: "Published",
sortBy: "PUBLISHED_TIME",
nextToken: nextToken,
}).promise();
for (const index in listVersionsResp.versions) {
const version = listVersionsResp.versions[index];
core.debug(`Saw version ${version.version}`);
if (version.version.startsWith(prefix + ".")) {
try {
const listVersionsResp = await ca
.listPackageVersions({
domain: domainName,
format: format,
package: packageName,
repository: repositoryName,
status: "Published",
sortBy: "PUBLISHED_TIME",
nextToken: nextToken,
})
.promise();
for (const index in listVersionsResp.versions) {
const version = listVersionsResp.versions[index];
core.debug(`Saw version ${version.version}`);
if (version.version.startsWith(prefix + ".")) {
return version.version;
}
}
nextToken = listVersionsResp.nextToken;
} catch (e) {
if (e.code === "ResourceNotFoundException") {
/**
* In the case the package cannot be found on code artifact, we return a null.
* This may happen because the package is not yet created in code artifact.
*/
return null
} else {
throw e
}
}
nextToken = listVersionsResp.nextToken;
} while (nextToken !== undefined);
return null;
}
Expand Down

0 comments on commit 29b7fa0

Please sign in to comment.