Skip to content

Commit

Permalink
Merge pull request #9 from CondeNast/fix/semver-pre-release
Browse files Browse the repository at this point in the history
fix(run): handle version strings aren't strictly semver
  • Loading branch information
garryyao authored Jan 5, 2024
2 parents 747bf9c + 788e6b4 commit 5e4e334
Show file tree
Hide file tree
Showing 4 changed files with 547 additions and 36 deletions.
7 changes: 4 additions & 3 deletions lib/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getInput, info as logInfo } from "@actions/core";
import { getOctokit } from "@actions/github";
import { diff } from "semver";
import { diff, coerce } from "semver";
import { addLabelsToPR, tryAutoMergePR, autoApprovePR } from "./utils";

const SNYK_UPGRADE_PR_TITLE_REGEXP = /\[Snyk\].+?[Uu]pgrade (.+?) from (.+?) to (.+?)$/;
Expand Down Expand Up @@ -58,8 +58,9 @@ export const run = async () => {
const matches = pr.title.match(SNYK_UPGRADE_PR_TITLE_REGEXP);
if (matches) {
let pkgName = matches[1];
let from = matches[2];
let to = matches[3];
let from = coerce(matches[2]);
let to = coerce(matches[3]);
if (from === null || to === null) continue;
diffType = diff(from, to);
}

Expand Down
42 changes: 9 additions & 33 deletions test/__fixtures/pulls.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"parent": null
}
],
"labels": [ ],
"labels": [],
"milestone": null,
"draft": false,
"commits_url": "https://api.github.com/repos/CondeNast/journey-purchase/pulls/1017/commits",
Expand Down Expand Up @@ -289,11 +289,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down Expand Up @@ -418,11 +414,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down Expand Up @@ -618,7 +610,7 @@
"parent": null
}
],
"labels": [ ],
"labels": [],
"milestone": null,
"draft": false,
"commits_url": "https://api.github.com/repos/CondeNast/journey-purchase/pulls/1015/commits",
Expand Down Expand Up @@ -743,11 +735,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down Expand Up @@ -872,11 +860,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down Expand Up @@ -1072,7 +1056,7 @@
"parent": null
}
],
"labels": [ ],
"labels": [],
"milestone": null,
"draft": false,
"commits_url": "https://api.github.com/repos/CondeNast/journey-purchase/pulls/1016/commits",
Expand Down Expand Up @@ -1197,11 +1181,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down Expand Up @@ -1326,11 +1306,7 @@
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
"martech",
"order-forms",
"subscriptions"
],
"topics": ["martech", "order-forms", "subscriptions"],
"visibility": "internal",
"forks": 1,
"open_issues": 35,
Expand Down
Loading

0 comments on commit 5e4e334

Please sign in to comment.