-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mordred-source-github-issues
- Loading branch information
Showing
11 changed files
with
201 additions
and
43 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
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,20 @@ | ||
{ | ||
"version": "0.2.0", | ||
"name": "mordred-source-github-issues", | ||
"files": [ | ||
"dist" | ||
], | ||
"main": "dist/index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc --watch", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"dependencies": { | ||
"axios": "0.20.0" | ||
}, | ||
"peerDependencies": { | ||
"mordred": "^0.1.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import axios from 'axios' | ||
|
||
export const GithubIssueNodeType = 'GithubIssue' | ||
|
||
export const fetchIssues = async ({ | ||
token, | ||
user, | ||
repo, | ||
}: { | ||
token?: string | ||
user: string | ||
repo: string | ||
}) => { | ||
const { data } = await axios.get( | ||
`https://api.github.com/repos/${user}/${repo}/issues?per_page=100`, | ||
{ | ||
headers: { | ||
Authorization: token ? `Bearer ${token}` : null, | ||
}, | ||
}, | ||
) | ||
return data.map((item: any) => ({ | ||
id: item.id, | ||
type: GithubIssueNodeType, | ||
mime: 'text/markdown', | ||
title: item.title, | ||
content: item.body, | ||
createdAt: item.created_at, | ||
updatedAt: item.updated_at, | ||
comments: item.comments, | ||
labels: item.labels, | ||
})) | ||
} |
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,51 @@ | ||
import { relative, join } from 'path' | ||
import { PluginFactory } from 'mordred' | ||
import { fetchIssues } from './api' | ||
|
||
const plugin: PluginFactory<{ token?: string; user: string; repo: string }> = ( | ||
ctx, | ||
{ token, user, repo }, | ||
) => { | ||
const gql = ctx.gql | ||
return { | ||
name: 'source-github-issues', | ||
|
||
getSchema() { | ||
return gql` | ||
type GithubIssueNode { | ||
id: ID! | ||
mime: String! | ||
title: String | ||
content: String! | ||
createdAt: String! | ||
updatedAt: String! | ||
comments: Int | ||
labels: [GithubIssueNodeLabel!] | ||
} | ||
type GithubIssueNodeLabel { | ||
id: ID! | ||
name: String! | ||
color: String! | ||
description: String | ||
} | ||
type GithubIssueConnection { | ||
nodes: [GithubIssueNode!]! | ||
} | ||
extend type Query { | ||
allGithubIssue: GithubIssueConnection | ||
} | ||
` | ||
}, | ||
|
||
createNodes() { | ||
return fetchIssues({ token, user, repo }) | ||
}, | ||
|
||
getResolvers: () => relative(ctx.outDir, join(__dirname, 'resolvers')), | ||
} | ||
} | ||
|
||
export default plugin |
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,14 @@ | ||
import { GithubIssueNodeType } from './api' | ||
|
||
export default ({ nodes }: { nodes: any[] }) => { | ||
return { | ||
Query: { | ||
allGithubIssue() { | ||
const result = nodes.filter((node) => node.type === GithubIssueNodeType) | ||
return { | ||
nodes: result, | ||
} | ||
}, | ||
}, | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
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
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 |
---|---|---|
|
@@ -3082,6 +3082,13 @@ aws4@^1.8.0: | |
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.1.tgz#7e33d8f7d449b3f673cd72deb9abdc552dbe528e" | ||
integrity sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug== | ||
|
||
[email protected]: | ||
version "0.20.0" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.20.0.tgz#057ba30f04884694993a8cd07fa394cff11c50bd" | ||
integrity sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA== | ||
dependencies: | ||
follow-redirects "^1.10.0" | ||
|
||
axios@^0.19.0: | ||
version "0.19.2" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" | ||
|
@@ -5306,6 +5313,11 @@ [email protected]: | |
dependencies: | ||
debug "=3.1.0" | ||
|
||
follow-redirects@^1.10.0: | ||
version "1.13.0" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" | ||
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== | ||
|
||
for-in@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" | ||
|