Skip to content

Commit 9adb1ff

Browse files
feat: adding repository param validation
1 parent 99bcf2b commit 9adb1ff

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

index.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const buildHeader = (fileA, fileB) => `diff --git a/${fileA} b/${fileB}\n` + `--
1111

1212
const getContent = async (github, owner, repo, path, commit) => {
1313
try {
14-
const res = await github.repos.getContent({
14+
const { data } = await github.repos.getContent({
1515
owner,
1616
repo,
1717
path,
1818
ref: commit,
1919
});
2020

21-
return res.data.content;
21+
return data.content;
2222
} catch (err) {
2323
try {
2424
const apiError = JSON.parse(err);
@@ -33,13 +33,13 @@ const getContent = async (github, owner, repo, path, commit) => {
3333
});
3434

3535
const { sha } = gitTree.tree.find((file) => file.path === path) || {};
36-
const data = await github.gitdata.getBlob({
36+
const { content } = await github.gitdata.getBlob({
3737
owner,
3838
repo,
3939
sha,
4040
});
4141

42-
return data.content;
42+
return content;
4343
}
4444

4545
throw err;
@@ -114,27 +114,27 @@ const getContentByStatus = async ({ github, owner, repo, base, head, file }) =>
114114

115115
const comparePackageVersions = async (github, owner, repo, base, head) => {
116116
try {
117-
const res = await github.repos.compareCommits({
117+
const { data } = await github.repos.compareCommits({
118118
owner,
119119
repo,
120120
base,
121121
head,
122122
});
123123

124-
const comparedCommits = res.data.files.map((file) => {
125-
const content = {
126-
github,
127-
owner,
128-
repo,
129-
base,
130-
head,
131-
file,
132-
};
133-
134-
return getContentByStatus(content);
135-
});
124+
const commits = await Promise.all(
125+
data.files.map((file) => {
126+
const content = {
127+
github,
128+
owner,
129+
repo,
130+
base,
131+
head,
132+
file,
133+
};
136134

137-
const commits = await Promise.all(comparedCommits);
135+
return getContentByStatus(content);
136+
})
137+
);
138138

139139
return commits;
140140
} catch (err) {
@@ -156,6 +156,10 @@ const nodeGithubDiff = async ({ repository, base, head, githubToken }) => {
156156
});
157157

158158
const [owner, repo] = repository.split('/');
159+
if (!owner || !repo) {
160+
throw new Error('Repository param should have "owner/repo" pattern');
161+
}
162+
159163
const data = await comparePackageVersions(github, owner, repo, base, head);
160164

161165
return data;

0 commit comments

Comments
 (0)