-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGithubClient.js
55 lines (48 loc) · 1.29 KB
/
GithubClient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { graphql } = require('@octokit/graphql');
const createIssueQuery = `mutation createIssue($repository: ID!, $title: String!, $description: String) {
createIssue(input: {repositoryId: $repository, title: $title, body: $description}) {
issue {
title,
body,
url
}
}
}`;
const findRepositoryQuery = `query findRepository($name: String!) {
search(first: 10, type: REPOSITORY, query: $name) {
edges {
node {
... on Repository {
nameWithOwner,
id
}
}
}
}
}`;
const GithubClient = (config, graphqlFetcher = graphql) => {
const graphqlQuery = (query, variables = {}) =>
graphqlFetcher({
query,
...variables,
baseUrl: config.baseUrl,
headers: {
authorization: `token ${config.token}`,
},
});
const createIssue = async ({ repository, title, description}) => {
return await graphqlQuery(createIssueQuery, {
repository,
title,
description,
});
};
const findRepository = async ({ name }) => {
return await graphqlQuery(findRepositoryQuery, { name });
};
return {
createIssue,
findRepository,
};
};
module.exports = { GithubClient };