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

Issues/80 add technology and difficulty #82

Merged
merged 4 commits into from
Jun 20, 2019
Merged
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
81 changes: 41 additions & 40 deletions Github/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const today = new Date();
const day = 24 * 60 * 60 * 1000;

module.exports.getRepos = recency => {
const reposNames = [];
return new Promise((resolve, reject) => {
request.get(
{
Expand All @@ -33,14 +32,16 @@ module.exports.getRepos = recency => {
console.log('Error:', res.statusMessage);
reject(res.Error);
} else {
const repos = JSON.parse(data);
repos.forEach(repo => {
if (today - new Date(repo.pushed_at) < recency) {
reposNames.push({
const reposNames = JSON.parse(data)
.filter(rep => {
return today - new Date(rep.pushed_at) < recency;
})
.map(repo => {
return {
name: repo.name,
});
}
});
language: repo.language,
belavina marked this conversation as resolved.
Show resolved Hide resolved
};
});
resolve(reposNames);
}
},
Expand All @@ -49,8 +50,6 @@ module.exports.getRepos = recency => {
};

const getCommits = branch => {
let simplifiedCommit = {};
const commitsPerBranch = [];
return new Promise((resolve, reject) => {
request.get(
{
Expand All @@ -62,13 +61,19 @@ const getCommits = branch => {
console.log('Error:', res.statusMessage);
reject(new Error('Unable to get commits.'));
} else {
JSON.parse(data).forEach(singleCommit => {
const {
commit: { author },
} = singleCommit;
if (today - new Date(author.date) < day) {
const commitsPerBranch = JSON.parse(data)
.filter(singleCommit => {
const {
commit: { author },
} = singleCommit;
return today - new Date(author.date) < day;
})
.map(singleCommit => {
const {
commit: { author },
} = singleCommit;
const time = new Date(author.date);
simplifiedCommit = {
return {
author: {
name: author.name,
date: time.toLocaleString('en-US', {
Expand All @@ -79,9 +84,7 @@ const getCommits = branch => {
repoName: branch.repo,
branchName: branch.br.name,
};
commitsPerBranch.push(simplifiedCommit);
}
});
});
resolve(commitsPerBranch);
}
},
Expand All @@ -104,12 +107,11 @@ const getBranches = repo => {
repo: repo.name,
branches: [],
};
JSON.parse(data).forEach(branch => {
branch.repo = repo.name;
listOfBranches.branches.push({
listOfBranches.branches = JSON.parse(data).map(branch => {
return {
name: branch.name,
sha: branch.commit.sha,
});
};
});
resolve(listOfBranches);
}
Expand All @@ -120,9 +122,8 @@ const getBranches = repo => {

module.exports.getAllCommitsTogether = branches => {
return new Promise((resolve, reject) => {
let promises = [];
branches.forEach(branch => {
promises.push(getBranches(branch));
let promises = branches.map(branch => {
return getBranches(branch);
});
Promise.all(promises)
.then(branchesPerRepo => {
Expand Down Expand Up @@ -159,27 +160,27 @@ const getIssuesFromRepo = repo => {
return new Promise((resolve, reject) => {
request.get(
{
url: `/repos/Seneca-CDOT/${repo}/issues`,
url: `/repos/Seneca-CDOT/${repo.name}/issues`,
qs: { labels: 'help wanted' },
},
(err, res, data) => {
if (res.statusCode !== 200) {
console.log('Error:', res.statusMessage);
reject(new Error('Unable to get repos.'));
} else {
const filteredIssues = [];
console.log(data.length);
JSON.parse(data).forEach(issue => {
const assigs = [];
const filteredIssues = JSON.parse(data).map(issue => {
let assigs = [];
if (issue.assignees.length !== 0) {
issue.assignees.forEach(assignee => {
assigs.push({
assigs = issue.assignees.map(assignee => {
return {
name: assignee.login,
avatar: assignee.avatar_url,
});
};
});
}
filteredIssues.push({
const labelsInIssue = issue.labels.map(label => label.name);

return {
ra: issue.user.login,
repository: issue.repository_url.slice(
issue.repository_url.lastIndexOf('/') + 1,
Expand All @@ -188,7 +189,8 @@ const getIssuesFromRepo = repo => {
number: issue.number,
title: issue.title,
description: issue.body,
label: 'Help Wanted',
language: repo.language,
labels: labelsInIssue,
state: issue.state,
assignees: assigs,
milestone: issue.milestone,
Expand All @@ -198,7 +200,7 @@ const getIssuesFromRepo = repo => {
updated: new Date(issue.updated_at).toLocaleString('en-US', {
timeZone: 'America/Toronto',
}),
});
};
});
resolve(filteredIssues);
}
Expand All @@ -209,9 +211,8 @@ const getIssuesFromRepo = repo => {

module.exports.getIssues = repos => {
return new Promise((resolve, reject) => {
const promises = [];
repos.forEach(repo => {
promises.push(getIssuesFromRepo(repo.name));
const promises = repos.map(repo => {
return getIssuesFromRepo(repo);
});
Promise.all(promises)
.then(arraysOfIssues => {
Expand Down