-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.ts
36 lines (29 loc) · 905 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { PackageManifest } from "query-registry";
const githubUrlRegex =
/(?:git\+)?https?:\/\/github\.com\/([^\/]+\/[^\/]+)\.git/; // TODO: Don't trust this, it's chatgbd :)
export function extractOwnerAndRepo(
repositoryUrl: string,
): [string, string] | null {
const match = repositoryUrl.match(githubUrlRegex);
if (match) {
const [owner, repo] = match[1].split("/");
return [owner, repo];
} else {
return null;
}
}
export function extractRepository(manifest: PackageManifest) {
return typeof manifest.repository === "string"
? manifest.repository
: manifest.repository?.url;
}
const commitLength = 7;
/*
* "09efd0553374ff7d3e62b79378e3184f5eb57571" => "09efd05"
*/
export function abbreviateCommitHash(fullHash: string) {
return fullHash.substring(0, commitLength);
}
export function isPullRequest(ref: string) {
return !Number.isNaN(Number(ref))
}