Skip to content

Commit

Permalink
feat: add GitHubClient logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ovsds committed Aug 1, 2024
1 parent 2a6b73e commit dece5d0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
id: test-run
uses: ./
with:
release_version_regexp: 'test-v?(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+).*$'
release_version_regexp: '^test-v?(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+).*$'

- name: Assert placeholder
uses: nick-fields/assert-action@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Get Next Release Version Action

[![CI](https://github.com/datalens-tech/get-next-release-version-action/workflows/Check%20PR/badge.svg)](https://github.com/ovsds/get-next-release-version-action/actions?query=workflow%3A%22%22Check+PR%22%22)
[![CI](https://github.com/datalens-tech/get-next-release-version-action/workflows/Check%20PR/badge.svg)](https://github.com/datalens-tech/get-next-release-version-action/actions?query=workflow%3A%22%22Check+PR%22%22)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Get%20Next%20Release%20Version-blue.svg)](https://github.com/marketplace/actions/get-next-release-version)

Get Next Release Version Action
Expand Down
24 changes: 19 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class GitHubClient {
}));
});
}
compareCommits(owner, repo, base, head) {
return __awaiter(this, void 0, void 0, function* () {
const data = yield this.octokitClient.repos.compareCommits({
owner,
repo,
base,
head,
});
return data.data.status;
});
}
getLatestRelease(owner, repo, targetCommitish, prerelease, releaseVersionRegexp) {
return __awaiter(this, void 0, void 0, function* () {
let page = 1;
Expand All @@ -51,16 +62,19 @@ class GitHubClient {
const releases = yield this.getReleases(owner, repo, perPage, page);
this.logger(`Fetched ${releases.length} releases from page ${page}`);
for (const release of releases) {
if (targetCommitish !== "" && release.targetCommitish !== targetCommitish) {
this.logger(`Skipping release ${release.tagName} because target commitish does not match`);
continue;
if (targetCommitish !== "") {
const status = yield this.compareCommits(owner, repo, targetCommitish, release.tagName);
if (status !== "behind" && status !== "identical") {
this.logger(`Skipping release ${release.tagName} because it is not based on the target commitish(${targetCommitish})`);
continue;
}
}
if (prerelease !== null && release.prerelease !== prerelease) {
this.logger(`Skipping release ${release.tagName} because prerelease status does not match`);
this.logger(`Skipping release ${release.tagName} because prerelease status does not match, expected ${prerelease}, got ${release.prerelease}`);
continue;
}
if (!releaseVersionRegexp.test(release.tagName)) {
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp`);
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp(${releaseVersionRegexp})`);
continue;
}
return release;
Expand Down
30 changes: 25 additions & 5 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class GitHubClient {
}));
}

async compareCommits(owner: string, repo: string, base: string, head: string): Promise<string> {
const data = await this.octokitClient.repos.compareCommits({
owner,
repo,
base,
head,
});

return data.data.status;
}

async getLatestRelease(
owner: string,
repo: string,
Expand All @@ -77,18 +88,27 @@ class GitHubClient {
this.logger(`Fetched ${releases.length} releases from page ${page}`);

for (const release of releases) {
if (targetCommitish !== "" && release.targetCommitish !== targetCommitish) {
this.logger(`Skipping release ${release.tagName} because target commitish does not match`);
continue;
if (targetCommitish !== "") {
const status = await this.compareCommits(owner, repo, targetCommitish, release.tagName);
if (status !== "behind" && status !== "identical") {
this.logger(
`Skipping release ${release.tagName} because it is not based on the target commitish(${targetCommitish})`,
);
continue;
}
}

if (prerelease !== null && release.prerelease !== prerelease) {
this.logger(`Skipping release ${release.tagName} because prerelease status does not match`);
this.logger(
`Skipping release ${release.tagName} because prerelease status does not match, expected ${prerelease}, got ${release.prerelease}`,
);
continue;
}

if (!releaseVersionRegexp.test(release.tagName)) {
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp`);
this.logger(
`Skipping release ${release.tagName} because it does not match the version regexp(${releaseVersionRegexp})`,
);
continue;
}

Expand Down

0 comments on commit dece5d0

Please sign in to comment.