1
1
import R from 'ramda'
2
2
import { timeout } from 'promise-timeout'
3
3
4
- import { ISSUE_ADDR } from '@config'
5
-
6
4
import { TIMEOUT_SEC , restEndpoint } from './config'
7
- import { graphqlClient , restpClient } from './client'
5
+ import { graphqlClient , restClient } from './client'
8
6
9
7
import S from './schema'
10
8
11
- const baseInfoQuery = ( owner , name ) =>
12
- graphqlClient . request ( S . repository , { owner, name} )
9
+ const baseInfoQuery = ( owner , name ) => {
10
+ return graphqlClient . request ( S . repository , { owner, name} )
11
+ }
13
12
14
13
const contributorsQuery = ( owner , name ) => {
15
14
const path = 'contributors?page=1&per_page=8'
16
15
const api = `${ restEndpoint } /repos/${ owner } /${ name } /${ path } `
17
16
18
- return restpClient ( `${ api } ` )
17
+ return restClient ( `${ api } ` )
18
+ }
19
+
20
+ const readmeQuery = ( owner , name ) => {
21
+ return restClient ( `${ restEndpoint } /repos/${ owner } /${ name } /readme` , 'raw' )
19
22
}
20
23
21
24
export const searchRepoPromise = ( owner , name ) =>
22
25
Promise . all ( [
23
26
timeout ( baseInfoQuery ( owner , name ) , TIMEOUT_SEC ) ,
24
27
timeout ( contributorsQuery ( owner , name ) , TIMEOUT_SEC ) ,
28
+ timeout ( readmeQuery ( owner , name ) , TIMEOUT_SEC ) ,
25
29
] )
26
30
27
31
const getRelaseTag = releases => {
@@ -37,7 +41,8 @@ const getLicense = value => {
37
41
// transform to match our model
38
42
export const transformRepo = res => {
39
43
const baseInfoRes = res [ 0 ] . repository
40
- const contributorsRes = res [ 1 ] . data
44
+ const contributorsRes = res [ 1 ]
45
+ const readme = res [ 2 ]
41
46
const contributors = [ ]
42
47
43
48
R . forEach ( user => {
@@ -61,14 +66,9 @@ export const transformRepo = res => {
61
66
licenseInfo,
62
67
homepageUrl,
63
68
releases,
64
- object,
65
69
primaryLanguage,
66
70
} = baseInfoRes
67
71
68
- const readme = object
69
- ?object . text
70
- :`同步错误: 目前只同步源仓库中的 README.md 文件,如果源仓库中为 README.MD / readme.md / readme.MD 等格式可能会导致该错误。 如果是其他原因,[恳请提交 issue](${ ISSUE_ADDR } /new)`
71
-
72
72
return {
73
73
title :name ,
74
74
ownerName :owner . login ,