Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from Nirespire/stale-prs
Browse files Browse the repository at this point in the history
[Feature] Added stale commit styles and config #27
  • Loading branch information
Joe Attardi committed Nov 17, 2018
2 parents d0ff849 + e505e7d commit 7c4f16a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.json.sample
Expand Up @@ -19,6 +19,7 @@
"mergeRule": {
"positive": 2,
"negative": 0,
"staleHours": 0,
"neverRegexp": "DO NOT MERGE"
}
}
4 changes: 3 additions & 1 deletion server/configManager.js
Expand Up @@ -23,6 +23,7 @@ exports.updateConfig = function updateConfig(updatedConfig) {
config.repos = updatedConfig.repos;
config.comments = updatedConfig.comments;
config.mergeRule = updatedConfig.mergeRule;
config.staleHours = updatedConfig.staleHours;
neverMergeRegexp = new RegExp(updatedConfig.mergeRule.neverRegexp, 'i');
config.repos.sort();
emoji.init();
Expand All @@ -38,7 +39,8 @@ exports.hasMergeRules = function hasMergeRules() {
return config.mergeRule &&
_.isNumber(config.mergeRule.positive) &&
_.isNumber(config.mergeRule.negative) &&
_.isString(config.mergeRule.neverRegexp);
_.isString(config.mergeRule.neverRegexp) &&
_.isNumber(config.mergeRule.staleHours);
};

exports.getNeverMergeRegexp = function getNeverMergeRegexp() {
Expand Down
15 changes: 14 additions & 1 deletion server/githubService.js
Expand Up @@ -103,6 +103,17 @@ function getPullRequestReviews(pr) {
});
}

function prIsStale(pr) {
const currentDate = new Date();
const staleHours = configManager.getConfig().mergeRule.staleHours;
if (staleHours > 0) {
const hoursBack = currentDate.getHours() - staleHours;
const previousDate = currentDate.setHours(hoursBack);
return new Date(pr.created).getTime() < previousDate;
}
return false;
}

exports.getRepo = function getRepo(owner, name) {
const config = configManager.getConfig();
return apiCall(`${config.apiBaseUrl}/repos/${owner}/${name}`);
Expand Down Expand Up @@ -133,8 +144,10 @@ exports.loadPullRequests = function loadPullRequests() {
if (config.mergeRule.neverRegexp && configManager.getNeverMergeRegexp().test(pr.title)) {
pr.unmergeable = true;
} else if (pr.positiveComments >= config.mergeRule.positive &&
pr.negativeComments <= config.mergeRule.negative) {
pr.negativeComments <= config.mergeRule.negative) {
pr.mergeable = true;
} else if (prIsStale(pr)) {
pr.stale = true;
}
});
}
Expand Down
17 changes: 17 additions & 0 deletions src/css/main.scss
Expand Up @@ -99,6 +99,23 @@ footer {
}
}

&.pull-request--stale {
background: #F4C542;
border-left: 36px solid #E2E600;

&:before {
color: #FFFFFF;
font-family: FontAwesome;
font-weight: normal;
font-style: normal;
display: inline-block;
text-decoration: inherit;
position: absolute;
margin-left: -34px;
content: "\f071";
}
}

.pull-request-info {
flex-grow: 1;
}
Expand Down
13 changes: 13 additions & 0 deletions src/js/components/EditDashboard.jsx
Expand Up @@ -22,6 +22,7 @@ class EditDashboard extends React.Component {
mergeRule: {
positive: 0,
negative: 0,
staleHours: 0,
neverRegexp: ''
}
}
Expand All @@ -38,6 +39,7 @@ class EditDashboard extends React.Component {
this.removeNegative = this.removeNegative.bind(this);
this.handleChangePositiveMergeRule = this.handleChangePositiveMergeRule.bind(this);
this.handleChangeNegativeMergeRule = this.handleChangeNegativeMergeRule.bind(this);
this.handleChangeStaleHours = this.handleChangeStaleHours.bind(this);
this.handleChangeNeverRegexp = this.handleChangeNeverRegexp.bind(this);
}

Expand All @@ -57,6 +59,11 @@ class EditDashboard extends React.Component {
this.setState({ config: this.state.config });
}

handleChangeStaleHours(event) {
this.state.config.mergeRule.staleHours = parseInt(event.target.value, 10);
this.setState({ config: this.state.config });
}

handleChangeNeverRegexp(event) {
this.state.config.mergeRule.neverRegexp = event.target.value;
this.setState({ config: this.state.config });
Expand Down Expand Up @@ -196,6 +203,12 @@ class EditDashboard extends React.Component {
onChange={this.handleChangeNegativeMergeRule}
/>

<div><label htmlFor="staleHours">Hours Till PR is Stale</label></div>
<input
type="number" id="staleHours" value={this.state.config.mergeRule.staleHours}
onChange={this.handleChangeStaleHours}
/>

<div><label htmlFor="neverMerge">Never merge regexp</label></div>
<input
type="text" id="neverMerge" value={this.state.config.mergeRule.neverRegexp}
Expand Down
3 changes: 3 additions & 0 deletions src/js/components/PullRequest.jsx
Expand Up @@ -11,12 +11,15 @@ import { Status } from './Status';
const CLASS_BASE = 'pull-request';
const CLASS_UNMERGEABLE = `${CLASS_BASE} ${CLASS_BASE}--unmergeable`;
const CLASS_MERGEABLE = `${CLASS_BASE} ${CLASS_BASE}--mergeable`;
const CLASS_STALE = `${CLASS_BASE} ${CLASS_BASE}--stale`;

function getPrClassName(pr) {
if (pr.unmergeable) {
return CLASS_UNMERGEABLE;
} else if (pr.mergeable) {
return CLASS_MERGEABLE;
} else if (pr.stale) {
return CLASS_STALE;
}

return CLASS_BASE;
Expand Down

0 comments on commit 7c4f16a

Please sign in to comment.