Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create prs #11

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN npm install --save-dev -y mocha --prefix /usr/local/
RUN npm install --save-dev -y sequelize --prefix /usr/local/
RUN npm install --save-dev -y pg pg-hstore --prefix /usr/local/
RUN npm install --save-dev -y dotenv --prefix /usr/local/
RUN npm install --save-dev -y cross-fetch --prefix /usr/local/

EXPOSE 4002/tcp

Expand Down
4 changes: 2 additions & 2 deletions lib/createPullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ async function createPullRequest(
const repo = await Repo.findOne({ where: { repo_id: repo_id }, include: PullRequest });
const json = JSON.stringify(repo, 2, null);
const repoObject = JSON.parse(json);
const pullRequests = repoObject.pullrequests;
const pullRequests = repoObject?.pullrequests;

//Check if repo has a pull request with the same defaultHash already
if(pullRequests !== []){
for(let i = 0; i < pullRequests.length; i++){
for(let i = 0; i < pullRequests?.length; i++){
if(pullRequests[i].defaultHash === defaultHash) {
return 403
}
Expand Down
32 changes: 31 additions & 1 deletion lib/createRepo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Repo } = require("../server/db");

const createPullRequest = require("./createPullRequest")
const fetch = require("cross-fetch")
async function createRepo(
/*owner:*/ owner,
/*repo:*/ repo_id,
Expand All @@ -13,6 +14,35 @@ async function createRepo(
repo_id: repo_id,
contributor_id: contributor_id,
});

fetch(`https://api.github.com/repos/${repo_id}/pulls`)
.then(res => {
if (res.status >= 400) {
throw new Error("Bad response from server");
}
return res.json();
})
.then(data => {
data.map(async (pull) => {
await createPullRequest(
repo_id.split('_')[0],
repo_id,
pull.head.sha,
pull.head.sha,
pull.head.sha,
pull.head.sha,
pull.url,
pull.base.ref,
pull.head.ref,
pull.title,
`issue_${pull.number}`,
)
})
})
.catch(err => {
console.error(err);
});

console.log(`created repo ${repo_id} successfully!`);
return 201;
} catch (error) {
Expand Down
82 changes: 82 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "/usr/local/node_modules/mocha/bin/mocha.js"
},
"dependencies": {
"cross-fetch": "^4.0.0",
"express": "^4.17.1",
"express-graphql": "^0.12.0",
"graphql": "^16.0.1",
Expand Down