auto-approver
Advanced tools
Comparing version 1.6.1 to 1.6.2
@@ -0,7 +1,12 @@ | ||
/** @see https://docs.github.com/en/rest/reference/pulls#get-a-pull-request */ | ||
interface GitHubPullRequest { | ||
head: { | ||
/** The branch name */ | ||
ref: string; | ||
/** The commit SHA-1 hash */ | ||
sha: string; | ||
}; | ||
/** The pull request number */ | ||
number: number; | ||
/** The pull request title */ | ||
title: string; | ||
@@ -12,3 +17,3 @@ } | ||
pullNumber: number; | ||
status: 'bad' | 'ok'; | ||
status: 'bad' | 'good'; | ||
} | ||
@@ -47,3 +52,3 @@ export interface ApproverConfig { | ||
private checkConfig; | ||
private checkRepository; | ||
private checkRepositorySlug; | ||
approveByMatch(regex: RegExp, repositories?: Repository[]): Promise<RepositoryResult[]>; | ||
@@ -50,0 +55,0 @@ private getMatchingRepositories; |
@@ -49,11 +49,11 @@ "use strict"; | ||
} | ||
checkRepository(repositorySlug) { | ||
const gitHubUsernameRegex = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i; | ||
const gitHubRepositoryRegex = /^[\w-.]{0,100}$/i; | ||
checkRepositorySlug(repositorySlug) { | ||
const gitHubUsernameRegex = /^\w+(?:-?\w+){0,37}\w$/i; | ||
const gitHubRepositoryRegex = /^[\w-.]{0,99}\w$/i; | ||
const [userName, repositoryName] = repositorySlug.trim().replace(/^\//, '').replace(/\/$/, '').split('/'); | ||
if (!gitHubUsernameRegex.test(userName) || !gitHubRepositoryRegex.test(repositoryName)) { | ||
if (!repositoryName || !gitHubUsernameRegex.test(userName) || !gitHubRepositoryRegex.test(repositoryName)) { | ||
this.logger.warn(`Invalid GitHub repository slug "${repositorySlug}". Skipping.`); | ||
return false; | ||
} | ||
return repositorySlug; | ||
return true; | ||
} | ||
@@ -92,3 +92,3 @@ approveByMatch(regex, repositories) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const actionResult = { pullNumber, status: 'ok' }; | ||
const actionResult = { pullNumber, status: 'good' }; | ||
try { | ||
@@ -109,3 +109,3 @@ if (!this.config.dryRun) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const actionResult = { pullNumber, status: 'ok' }; | ||
const actionResult = { pullNumber, status: 'good' }; | ||
try { | ||
@@ -126,5 +126,3 @@ if (!this.config.dryRun) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const repositorySlugs = this.config.projects.gitHub | ||
.map(repositorySlug => this.checkRepository(repositorySlug)) | ||
.filter(Boolean); | ||
const repositorySlugs = this.config.projects.gitHub.filter(repositorySlug => this.checkRepositorySlug(repositorySlug)); | ||
const repositoriesPromises = repositorySlugs.map((repositorySlug) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -131,0 +129,0 @@ const pullRequests = yield this.getPullRequestsBySlug(repositorySlug); |
@@ -0,1 +1,8 @@ | ||
## [1.6.1](https://github.com/ffflorian/auto-approver/compare/v1.6.0...v1.6.1) (2020-09-18) | ||
### Bug Fixes | ||
* Dry-run option format ([f425ea7](https://github.com/ffflorian/auto-approver/commit/f425ea76ae15db977e43aeeb55c5268b7fb0ac5c)) | ||
# [1.6.0](https://github.com/ffflorian/auto-approver/compare/v1.5.0...v1.6.0) (2020-09-17) | ||
@@ -2,0 +9,0 @@ |
@@ -52,3 +52,3 @@ #!/usr/bin/env node | ||
const commentedRepositories = commentResult.reduce((count, repository) => count + repository.actionResults.length, 0); | ||
const pluralSingular = util_1.getPlural('request', commentedRepositories); | ||
const pluralSingular = util_1.pluralize('request', commentedRepositories); | ||
logger.info(`Commented "${configFileData.useComment}" on ${commentedRepositories} pull ${pluralSingular}.`); | ||
@@ -59,3 +59,3 @@ } | ||
const approvedRepositories = approveResult.reduce((count, repository) => count + repository.actionResults.length, 0); | ||
const pluralSingular = util_1.getPlural('request', approvedRepositories); | ||
const pluralSingular = util_1.pluralize('request', approvedRepositories); | ||
logger.info(`Approved ${approvedRepositories} pull ${pluralSingular}.`); | ||
@@ -92,3 +92,3 @@ } | ||
const repositories = allRepositories.map(repository => { | ||
const prText = util_1.getPlural('PR', repository.pullRequests.length); | ||
const prText = util_1.pluralize('PR', repository.pullRequests.length); | ||
return `${repository.repositorySlug} (${repository.pullRequests.length} open ${prText})`; | ||
@@ -95,0 +95,0 @@ }); |
@@ -34,5 +34,7 @@ { | ||
"eslint-plugin-typescript-sort-keys": "1.3.0", | ||
"http-status-codes": "2.1.4", | ||
"husky": "4.3.0", | ||
"jasmine": "3.6.1", | ||
"lint-staged": "10.4.0", | ||
"nock": "13.0.4", | ||
"prettier": "2.1.2", | ||
@@ -43,3 +45,3 @@ "publish-flat": "1.4.1", | ||
"ts-node": "9.0.0", | ||
"typescript": "4.0.2" | ||
"typescript": "4.0.3" | ||
}, | ||
@@ -109,3 +111,3 @@ "engines": { | ||
}, | ||
"version": "1.6.1" | ||
"version": "1.6.2" | ||
} |
@@ -1,1 +0,1 @@ | ||
export declare function getPlural(word: string, count: number, postfix?: string): string; | ||
export declare function pluralize(word: string, count: number, postfix?: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPlural = void 0; | ||
function getPlural(word, count, postfix = 's') { | ||
exports.pluralize = void 0; | ||
function pluralize(word, count, postfix = 's') { | ||
return count === 1 ? word : `${word}${postfix}`; | ||
} | ||
exports.getPlural = getPlural; | ||
exports.pluralize = pluralize; | ||
//# sourceMappingURL=util.js.map |
Sorry, the diff of this file is not supported yet
69329
355
31