File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,21 @@ const fetchOrgReposListByLogin = async (login) => {
42
42
return repoList
43
43
}
44
44
45
+ const fetchRepoByFullName = async ( fullName ) => {
46
+ debug ( `Fetching repository (${ fullName } )...` )
47
+ ensureGithubToken ( )
48
+ const octokit = new Octokit ( { auth : process . env . GITHUB_TOKEN } )
49
+ const { data } = await octokit . request ( 'GET /repos/{owner}/{repo}' , {
50
+ owner : fullName . split ( '/' ) [ 0 ] ,
51
+ repo : fullName . split ( '/' ) [ 1 ]
52
+ } )
53
+ return data
54
+ }
55
+
45
56
const github = {
46
57
fetchOrgByLogin,
47
58
fetchOrgReposListByLogin,
59
+ fetchRepoByFullName
48
60
}
49
61
50
62
module . exports = {
Original file line number Diff line number Diff line change 1
1
const debug = require ( 'debug' ) ( 'store' )
2
2
3
+ const upsertGithubRepository = knex => async ( repository , orgId ) => {
4
+ debug ( `Upserting repository (${ repository . full_name } )...` )
5
+
6
+ const existingRepository = await knex ( 'github_repositories' ) . where ( { full_name : repository . full_name } ) . first ( )
7
+ if ( existingRepository ) {
8
+ return knex ( 'github_repositories' ) . where ( { full_name : repository . full_name , github_organization_id : orgId } ) . update ( repository ) . returning ( '*' )
9
+ } else {
10
+ return knex ( 'github_repositories' ) . insert ( { ...repository , github_organization_id : orgId } ) . returning ( '*' )
11
+ }
12
+ }
13
+
3
14
const getAllGithubOrganizations = knex => async ( ) => {
4
15
debug ( 'Getting all GitHub organizations...' )
5
16
return knex ( 'github_organizations' ) . select ( )
@@ -41,7 +52,8 @@ const initializeStore = (knex) => {
41
52
addProject : addProject ( knex ) ,
42
53
addGithubOrganization : addGithubOrganization ( knex ) ,
43
54
getAllGithubOrganizations : getAllGithubOrganizations ( knex ) ,
44
- updateGithubOrganization : updateGithubOrganization ( knex )
55
+ updateGithubOrganization : updateGithubOrganization ( knex ) ,
56
+ upsertGithubRepository : upsertGithubRepository ( knex )
45
57
}
46
58
}
47
59
You can’t perform that action at this time.
0 commit comments