Skip to content

Commit

Permalink
feat: implement TimeToSolveIssues practice
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Jan 7, 2020
1 parent cfea49b commit bea4853
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/practices/LanguageIndependent/TimeToSolveIssuesPractice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import moment from 'moment';
import { PracticeContext } from '../../contexts/practice/PracticeContext';
import { PracticeEvaluationResult, PracticeImpact } from '../../model';
import { GitServiceUtils } from '../../services/git/GitServiceUtils';
import { DxPractice } from '../DxPracticeDecorator';
import { IPractice } from '../IPractice';

@DxPractice({
id: 'LanguageIndependent.TimeToSolveIssues',
name: 'Solve Issues Continuously',
impact: PracticeImpact.medium,
suggestion: 'Do not have an open Issues more than 60 days. Solve Issues continuously.',
reportOnlyOnce: true,
url: '',
//dependsOn: { practicing: ['LanguageIndependent.DoesPullRequests'] },
})
export class TimeToSolveIssuesPractice implements IPractice {
async isApplicable(): Promise<boolean> {
return true;
}

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
if (ctx.fileInspector === undefined || ctx.issueTrackingInspector === undefined) {
return PracticeEvaluationResult.unknown;
}

const repoName = GitServiceUtils.getRepoName(ctx.projectComponent.repositoryPath, ctx.projectComponent.path);
const ownerAndRepoName = GitServiceUtils.getOwnerAndRepoName(repoName);

//Both GitHub API and Bitbucket API returns open issues by default
const issues = await ctx.issueTrackingInspector.getIssues(ownerAndRepoName.owner, ownerAndRepoName.repoName);
const latestIssueUpdate = issues.items.map((item) => new Date(item.updatedAt || item.createdAt).getTime());

const daysInMilliseconds = moment.duration(60, 'days').asMilliseconds();
const now = Date.now();
const openPullRequestsTooLong = [];

latestIssueUpdate.forEach((issueDate) => {
if (now - issueDate > daysInMilliseconds) {
openPullRequestsTooLong.push(issueDate);
}
});

if (openPullRequestsTooLong.length === 0) {
return PracticeEvaluationResult.practicing;
}

return PracticeEvaluationResult.notPracticing;
}
}
2 changes: 2 additions & 0 deletions src/practices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DoesPullRequestsPractice } from './LanguageIndependent/DoesPullRequests
import { DependenciesVersionMinorPatchLevelPractice } from './JavaScript/DependenciesVersionMinorPatchLevel';
import { CorrectCommitMessagesPractice } from './LanguageIndependent/CorrectCommitMessagesPractice';
import { TimeToSolvePullRequestsPractice } from './LanguageIndependent/TimeToSolvePullRequestsPractice';
import { TimeToSolveIssuesPractice } from './LanguageIndependent/TimeToSolveIssuesPractice';

// register practices here
export const practices = [
Expand Down Expand Up @@ -53,4 +54,5 @@ export const practices = [
DoesPullRequestsPractice,
CorrectCommitMessagesPractice,
TimeToSolvePullRequestsPractice,
TimeToSolveIssuesPractice,
];

0 comments on commit bea4853

Please sign in to comment.