Skip to content

Commit 03141da

Browse files
authored
Merge pull request #42 from codecov/use-commit
Use commit hashes only
2 parents 88a933a + 3a7d32f commit 03141da

File tree

4 files changed

+203
-151
lines changed

4 files changed

+203
-151
lines changed

src/content/github/common/fetchers.ts

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,78 @@
11
import browser from "webextension-polyfill";
2-
import { MessageType } from "src/types";
2+
import {
3+
FileCoverageReportResponse,
4+
FileMetadata,
5+
MessageType,
6+
} from "src/types";
7+
8+
export async function getMetadata(url: string): Promise<FileMetadata> {
9+
const response = await fetch(url).then((response) => response.json());
10+
return {
11+
owner: response.payload.repo.ownerLogin,
12+
repo: response.payload.repo.name,
13+
path: response.payload.path,
14+
commit: response.payload.refInfo.currentOid,
15+
};
16+
}
317

4-
export async function getFlags(url: {
5-
[key: string]: string;
6-
}): Promise<string[]> {
18+
export async function getFlags(metadata: FileMetadata): Promise<string[]> {
719
const payload = {
820
service: "github",
9-
owner: url.owner,
10-
repo: url.repo,
21+
owner: metadata.owner,
22+
repo: metadata.repo,
1123
};
1224

13-
const flagsResponse = await browser.runtime.sendMessage({
25+
const response = await browser.runtime.sendMessage({
1426
type: MessageType.FETCH_FLAGS_LIST,
1527
payload,
1628
referrer: window.location.href,
1729
});
1830

19-
const flags = flagsResponse.ok ? flagsResponse.data.results : [];
31+
const flags = response.ok ? response.data.results : [];
2032

2133
return flags.map((f: any) => f.flag_name);
2234
}
2335

24-
export async function getComponents(url: {
25-
[key: string]: string;
26-
}): Promise<string[]> {
36+
export async function getComponents(metadata: FileMetadata): Promise<string[]> {
2737
const payload = {
2838
service: "github",
29-
owner: url.owner,
30-
repo: url.repo,
39+
owner: metadata.owner,
40+
repo: metadata.repo,
3141
};
3242

33-
const componentsResponse = await browser.runtime.sendMessage({
43+
const response = await browser.runtime.sendMessage({
3444
type: MessageType.FETCH_COMPONENTS_LIST,
3545
payload,
3646
referrer: window.location.href,
3747
});
3848

39-
const components = componentsResponse.ok ? componentsResponse.data : [];
49+
const components = response.ok ? response.data : [];
4050

4151
return components.map((c: any) => c.component_id);
4252
}
4353

4454
export async function getCommitReport(
45-
url: { [key: string]: string },
55+
metadata: FileMetadata,
4656
flag: string | undefined,
4757
component_id: string | undefined
48-
) {
49-
const commonPayload = {
58+
): Promise<FileCoverageReportResponse> {
59+
const payload = {
5060
service: "github",
51-
owner: url.owner,
52-
repo: url.repo,
53-
path: url.path,
61+
owner: metadata.owner,
62+
repo: metadata.repo,
63+
path: metadata.path,
64+
sha: metadata.commit,
5465
flag,
5566
component_id,
5667
};
5768

58-
// TODO: check if codecov can figure out whether branch or sha
59-
const shaResponse = await browser.runtime.sendMessage({
60-
type: MessageType.FETCH_COMMIT_REPORT,
61-
payload: {
62-
...commonPayload,
63-
sha: url.ref,
64-
},
65-
referrer: window.location.href,
66-
});
67-
68-
if (shaResponse.ok) {
69-
return shaResponse.data;
70-
}
71-
72-
const branchResponse = await browser.runtime.sendMessage({
69+
const response = await browser.runtime.sendMessage({
7370
type: MessageType.FETCH_COMMIT_REPORT,
74-
payload: {
75-
...commonPayload,
76-
branch: url.ref,
77-
},
71+
payload,
7872
referrer: window.location.href,
7973
});
8074

81-
return branchResponse.data;
75+
return response.data;
8276
}
8377

8478
export async function getPRReport(url: any) {

0 commit comments

Comments
 (0)