-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpullForkServer.js
executable file
·66 lines (58 loc) · 2.08 KB
/
pullForkServer.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
56
57
58
59
60
61
62
63
64
65
66
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
const cors = require('cors');
const { pullForkUtil } = require('./src/utils/pullForkUtil');
const { getPullRequest } = require('./src/utils/gitHubUtil');
const { gitHeadUtil } = require('./src/utils/gitHeadUtil');
(async () => {
var schema = buildSchema(`
type Query {
getPRfork(owner: String, repo: String, defaultHash: String, contributor_id: String): String,
}
`);
var root = {
getPRfork: async (args) => {
const defaultHash = args.defaultHash;
// User should do this instead and pass it in request so we don't overuse our github api.
console.log('owner ' + args.owner);
console.log('repo ' + args.repo);
console.log('defaultHash ' + defaultHash);
var baseRepoName = args.repo;
var baseRepoOwner = args.owner;
//console.log('contributor ' + resGetPR.contributor)
console.log('baseRepoName ' + baseRepoName);
//console.log('forkBranch ' + resGetPR.forkBranch)
var resGetPR = await getPullRequest(baseRepoOwner, baseRepoName, defaultHash);
var pullReqRepoHead = await gitHeadUtil(resGetPR.contributor, baseRepoName, resGetPR.forkBranch, 0);
console.log('pullReqRepoHead ' + pullReqRepoHead);
console.log(resGetPR.forkBranch);
const repoHash = pullForkUtil(
baseRepoName,
pullReqRepoHead,
`https://github.com/${resGetPR.contributor}/${baseRepoName}`,
resGetPR.forkBranch
);
console.log('repoHash ' + repoHash);
return repoHash;
}
};
var app = express();
//app.use(loggingMiddleware);
app.use(cors());
app.use(function (req, res, next) {
let originalSend = res.send;
res.send = function (data) {
console.log(data + '\n');
originalSend.apply(res, Array.from(arguments));
};
next();
});
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true
}));
app.listen(4001);
console.log('Running a GraphQL API server at localhost:4001/graphql');
})();