Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Jun 12, 2020
1 parent dd538f6 commit 1382f59
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
18 changes: 18 additions & 0 deletions lib/util/index.ts
Expand Up @@ -23,3 +23,21 @@ export async function resolveFile(file: string): Promise<string> {
}
return join(pkg, '../', file);
}

export function sampleSize(array: string[], n: number): string[] {
const length = array == null ? 0 : array.length;
if (!length || n < 1) {
return [];
}
// eslint-disable-next-line no-param-reassign
n = n > length ? length : n;
let index = 0;
const lastIndex = length - 1;
const result = [...array];
while (index < n) {
const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
[result[rand], result[index]] = [result[index], result[rand]];
index += 1;
}
return result.slice(0, n);
}
8 changes: 8 additions & 0 deletions lib/util/string.ts
Expand Up @@ -23,3 +23,11 @@ export function replaceAt(
content.substr(index + oldString.length)
);
}

export function camelCase(input: string): string {
return input
.replace(/(?:^\w|[A-Z]|\b\w)/g, (char, index) => {
return index === 0 ? char.toLowerCase() : char.toUpperCase();
})
.replace(/-/g, '');
}
4 changes: 2 additions & 2 deletions lib/versioning/ruby/version.ts
Expand Up @@ -24,9 +24,9 @@ const floor = (version: string): string =>
// istanbul ignore next
const incrementLastSegment = (version: string): string => {
const segments = create(version).release().getSegments();
const nextLast = parseInt(segments[segments.length - 1], 10) + 1;
const nextLast = parseInt(segments.pop(), 10) + 1;

return [...segments.slice(0, -1), nextLast].join('.');
return [...segments, nextLast].join('.');
};

// istanbul ignore next
Expand Down
17 changes: 1 addition & 16 deletions lib/workers/pr/index.ts
Expand Up @@ -8,6 +8,7 @@ import {
import { logger } from '../../logger';
import { PlatformPrOptions, Pr, platform } from '../../platform';
import { BranchStatus } from '../../types';
import { sampleSize } from '../../util';
import { BranchConfig, PrResult } from '../common';
import { getPrBody } from './body';
import { ChangeLogError } from './changelog';
Expand Down Expand Up @@ -522,19 +523,3 @@ export async function checkAutoMerge(
logger.debug('No automerge');
return false;
}

function sampleSize(array: string[], n: number) {
const length = array == null ? 0 : array.length;
if (!length || n < 1) {
return [];
}
n = n > length ? length : n;
let index = -1;
const lastIndex = length - 1;
const result = [...array];
while (++index < n) {
const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
[result[rand], result[index]] = [result[index], result[rand]];
}
return result.slice(0, n);
}
10 changes: 2 additions & 8 deletions tools/generate-imports.ts
@@ -1,6 +1,8 @@
import fs from 'fs-extra';
import shell from 'shelljs';

import { camelCase } from '../lib/util/string';

shell.echo('generating imports');
const newFiles = new Set();

Expand All @@ -25,14 +27,6 @@ async function updateFile(file: string, code: string): Promise<void> {
newFiles.add(file);
}

function camelCase(input: string) {
return input
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (char, index) {
return index === 0 ? char.toLowerCase() : char.toUpperCase();
})
.replace(/-/g, '');
}

async function generate({
path,
types,
Expand Down

0 comments on commit 1382f59

Please sign in to comment.