This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Github V4 Api For Chronological Tags (#31)
* Introduce Github V4 Api For Chronological Tags * Remove Consoles
- Loading branch information
Showing
14 changed files
with
1,590 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"jest": true | ||
}, | ||
"rules": { | ||
"max-len": ["error", 150] | ||
"max-len": ["error", 150], | ||
"no-debugger": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/connectors/GithubConnector.js → ...tors/GithubConnector/GithubConnectorV3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const config = require('../../config'); | ||
|
||
const { domain, v4Host, token } = config.get('github'); | ||
|
||
const GithubGraphQL = require('@octokit/graphql').defaults({ | ||
baseUrl: `${domain}/api` || v4Host, | ||
headers: { | ||
authorization: `bearer ${token}`, | ||
}, | ||
}); | ||
|
||
module.exports = GithubGraphQL; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => () => jest.fn(); |
48 changes: 48 additions & 0 deletions
48
src/connectors/GithubConnector/__tests__/GithubConnector.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const GithubConnector = require('..'); | ||
|
||
describe('GithubConnector', () => { | ||
it('should initialize with the v3 api by default', () => { | ||
const github = GithubConnector(); | ||
|
||
expect(Object.getOwnPropertyNames(github)).toMatchInlineSnapshot(` | ||
Array [ | ||
"hook", | ||
"plugin", | ||
"request", | ||
"authenticate", | ||
"activity", | ||
"apps", | ||
"authorization", | ||
"checks", | ||
"enterprise", | ||
"gists", | ||
"gitdata", | ||
"integrations", | ||
"issues", | ||
"migrations", | ||
"misc", | ||
"orgs", | ||
"projects", | ||
"pullRequests", | ||
"reactions", | ||
"repos", | ||
"search", | ||
"users", | ||
"getFirstPage", | ||
"getLastPage", | ||
"getNextPage", | ||
"getPreviousPage", | ||
"hasFirstPage", | ||
"hasLastPage", | ||
"hasNextPage", | ||
"hasPreviousPage", | ||
] | ||
`); | ||
}); | ||
|
||
it('should override the initial github v3 service with v4', () => { | ||
const github = GithubConnector(true); | ||
|
||
expect(github.name).toEqual('newApi'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const v3API = require('./GithubConnectorV3'); | ||
const v4API = require('./GithubConnectorV4'); | ||
const { apiVersion } = require('../../config').get('github'); | ||
|
||
module.exports = (overrideV4) => { | ||
const isV4 = apiVersion.includes('v4'); | ||
|
||
let GithubConnector = v3API; | ||
|
||
if (isV4 || overrideV4) { | ||
GithubConnector = v4API; | ||
} | ||
|
||
return GithubConnector; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
const { Github: github } = require('../connectors'); | ||
const logger = require('../logger'); | ||
const idx = require('idx'); | ||
|
||
const { Github } = require('../connectors'); | ||
|
||
const github = Github(true); | ||
|
||
module.exports = async function getTags(owner, repo) { | ||
let tags = []; | ||
let repository = []; | ||
try { | ||
tags = await github.repos.getTags({ owner, repo }); | ||
repository = await github({ | ||
query: `query GetTags($owner: String!, $repo: String!) { | ||
repository(owner: $owner, name: $repo) { | ||
refs( | ||
refPrefix: "refs/tags/" | ||
first: 100 | ||
orderBy: { field: TAG_COMMIT_DATE, direction: DESC } | ||
) { | ||
edges { | ||
node { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
}`, | ||
owner, | ||
repo, | ||
}); | ||
} catch (e) { | ||
throw e; | ||
} | ||
|
||
return tags.data; | ||
const { repository: rep } = repository; | ||
const response = idx(rep, _ => _.refs.edges) || []; | ||
|
||
// We need to put the tags back into their original format so that we can be backwards compatible with | ||
// the expected v3 response. | ||
const tags = response.reduce((acc, edge) => [...acc, { name: idx(edge, _ => _.node.name) || '' }], []); | ||
|
||
return tags; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.