@@ -11,14 +11,14 @@ const buildHeader = (fileA, fileB) => `diff --git a/${fileA} b/${fileB}\n` + `--
11
11
12
12
const getContent = async ( github , owner , repo , path , commit ) => {
13
13
try {
14
- const res = await github . repos . getContent ( {
14
+ const { data } = await github . repos . getContent ( {
15
15
owner,
16
16
repo,
17
17
path,
18
18
ref : commit ,
19
19
} ) ;
20
20
21
- return res . data . content ;
21
+ return data . content ;
22
22
} catch ( err ) {
23
23
try {
24
24
const apiError = JSON . parse ( err ) ;
@@ -33,13 +33,13 @@ const getContent = async (github, owner, repo, path, commit) => {
33
33
} ) ;
34
34
35
35
const { sha } = gitTree . tree . find ( ( file ) => file . path === path ) || { } ;
36
- const data = await github . gitdata . getBlob ( {
36
+ const { content } = await github . gitdata . getBlob ( {
37
37
owner,
38
38
repo,
39
39
sha,
40
40
} ) ;
41
41
42
- return data . content ;
42
+ return content ;
43
43
}
44
44
45
45
throw err ;
@@ -114,27 +114,27 @@ const getContentByStatus = async ({ github, owner, repo, base, head, file }) =>
114
114
115
115
const comparePackageVersions = async ( github , owner , repo , base , head ) => {
116
116
try {
117
- const res = await github . repos . compareCommits ( {
117
+ const { data } = await github . repos . compareCommits ( {
118
118
owner,
119
119
repo,
120
120
base,
121
121
head,
122
122
} ) ;
123
123
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
+ } ;
136
134
137
- const commits = await Promise . all ( comparedCommits ) ;
135
+ return getContentByStatus ( content ) ;
136
+ } )
137
+ ) ;
138
138
139
139
return commits ;
140
140
} catch ( err ) {
@@ -156,6 +156,10 @@ const nodeGithubDiff = async ({ repository, base, head, githubToken }) => {
156
156
} ) ;
157
157
158
158
const [ owner , repo ] = repository . split ( '/' ) ;
159
+ if ( ! owner || ! repo ) {
160
+ throw new Error ( 'Repository param should have "owner/repo" pattern' ) ;
161
+ }
162
+
159
163
const data = await comparePackageVersions ( github , owner , repo , base , head ) ;
160
164
161
165
return data ;
0 commit comments