Skip to content

Commit

Permalink
Support points in PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Feb 12, 2018
1 parent 0e0a363 commit 8514e5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/GitHub/Issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Issue {
return a.points < b.points ? 1 : -1;
}

constructor(id, number, title, points, body, state, labels, milestone, createdAt, closedAt) {
constructor(id, number, title, points, body, state, labels, milestone, createdAt, closedAt = null, pullRequest = null) {
this.id = id;
this.number = number;
this.title = title;
Expand All @@ -81,7 +81,7 @@ class Issue {
this.milestone = milestone;
this.createdAt = createdAt;
this.closedAt = closedAt;
this.pullRequest = null;
this.pullRequest = pullRequest;

if (this.milestone) {
this.milestone.issues.push(this);
Expand All @@ -104,6 +104,22 @@ class Issue {
return 'todo';
}

/**
* Set pull request
*
* @param {PullRequest} pullRequest
*/
setPullRequest(pullRequest) {
this.pullRequest = pullRequest;
}

/**
* Is issue open at given date?
*
* @param {Date} date
*
* @return {Boolean}
*/
isOpenAt(date) {
return !this.closedAt || this.closedAt > date;
}
Expand Down
10 changes: 9 additions & 1 deletion src/GitHub/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@ class Project {
const issues = this.fetchIssues(data.body, data.number);
const reviews = data.reviews ? data.reviews.map(Review.create) : [];

this.addPullRequest(PullRequest.create(Object.assign(data, { milestone, labels, issues, reviews })));
const pullRequest = this.addPullRequest(PullRequest.create(Object.assign(data, { milestone, labels, issues, reviews })));
const { title, points } = Issue.parseTitle(pullRequest.title);


if (points !== null) {
const { id, number, state, labels, createdAt } = pullRequest;
pullRequest.title = title;
this.addIssue(new Issue(id, number, title, points, data.body, state, labels, milestone, createdAt, null, pullRequest));
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub/PullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PullRequest {
if (this.issues) {
this.issues.forEach(issue => {
if (typeof issue !== 'number') {
issue.pullRequest = this;
issue.setPullRequest(this);
}
});
}
Expand Down

0 comments on commit 8514e5f

Please sign in to comment.