-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement TimeToSolveIssues practice
- Loading branch information
1 parent
cfea49b
commit bea4853
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/practices/LanguageIndependent/TimeToSolveIssuesPractice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters