Skip to content

Commit f53e201

Browse files
committed
Refactor version bump fetching into separate method
1 parent 25c0c68 commit f53e201

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

lib/Geth/GitHub/Hooks/Preprocessor.pm6

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,8 @@ method nqp-version-bump ($json) {
3131
and .<modified>[0] eq 'tools/build/NQP_REVISION'
3232
} or return;
3333

34-
given $!ua.get("$RAKUDO_API_URL/commits/$commit<id>") {
35-
unless .is-success {
36-
say "Failed to fetch Rakudo commit via API: "
37-
~ .status-line ~ .content;
38-
return;
39-
}
40-
41-
my $patch = try {
42-
CATCH { say "Failed to decode API JSON: $!"; return; }
43-
from-json(.content)<files>[0]<patch>;
44-
};
45-
46-
$json<geth-meta><ver-bump> = "$NQP_URL/compare/"
47-
~ $patch.lines[1,2.substr(1).join('...');
48-
}
34+
self.fetch-version-bump: "$RAKUDO_API_URL/commits/$commit<id>", $NQP_URL
35+
andthen $json<geth-meta><ver-bump> = $_;
4936
}
5037

5138
method moar-version-bump ($json) {
@@ -54,9 +41,15 @@ method moar-version-bump ($json) {
5441
and .<modified>[0] eq 'tools/build/MOAR_REVISION'
5542
} or return;
5643

57-
given $!ua.get("$NQP_API_URL/commits/$commit<id>") {
44+
self.fetch-version-bump: "$NQP_API_URL/commits/$commit<id>", $MOAR_URL
45+
andthen $json<geth-meta><ver-bump> = $_;
46+
}
47+
48+
method fetch-version-bump ($commit-url, $compare-url-part) {
49+
given $!ua.get($commit-url) {
5850
unless .is-success {
59-
say "Failed to fetch NQP commit via API: {.status-line ~ .content}";
51+
say "Failed to fetch $commit-url via API: "
52+
~ .status-line ~ .content;
6053
return;
6154
}
6255

@@ -65,7 +58,6 @@ method moar-version-bump ($json) {
6558
from-json(.content)<files>[0]<patch>;
6659
};
6760

68-
$json<geth-meta><ver-bump> = "$MOAR_URL/compare/"
69-
~ $patch.lines[1,2.substr(1).join('...');
61+
"$compare-url-part/compare/" ~ $patch.lines[1,2.substr(1).join('...');
7062
}
7163
}

0 commit comments

Comments
 (0)