Skip to content

Commit

Permalink
chore: format files according to new prettier version
Browse files Browse the repository at this point in the history
  • Loading branch information
tagoro9 committed May 29, 2020
1 parent 7bc91b5 commit 2350080
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/commands/Release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const cmd = (args: FotingoArguments, messenger: Messenger): Observable<Jo
);

return releaseInformation$.pipe(
tap(data => messenger.emit(`Creating release ${data.name}`, Emoji.SHIP)),
tap((data) => messenger.emit(`Creating release ${data.name}`, Emoji.SHIP)),
switchMap(jira.createRelease),
switchMap(jira.setIssuesFixVersion),
withLatestFrom(commandData$),
switchMap(([release, { useDefaults }]) =>
getReleaseNotes(args.config.release, messenger, release, useDefaults).pipe(
map(notes => ({
map((notes) => ({
notes,
release,
})),
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ const updateIssues = (jira: Tracker, messenger: Messenger) => (
): Observable<Review> =>
(zip(
of(pullRequest).pipe(
tap(pr => {
tap((pr) => {
if (pr.issues.length > 0) {
messenger.emit(
`Updating ${pr.issues.map(issue => issue.key).join(', ')} on Jira`,
`Updating ${pr.issues.map((issue) => issue.key).join(', ')} on Jira`,
Emoji.BOOKMARK,
);
}
}),
),
merge(
...pullRequest.issues.map(issue =>
...pullRequest.issues.map((issue) =>
merge(
jira.setIssueStatus(IssueStatus.IN_REVIEW, issue.key),
jira.addCommentToIssue(issue.key, `PR: ${pullRequest.url}`),
Expand All @@ -77,6 +77,6 @@ export const cmd = (args: FotingoArguments, messenger: Messenger): Observable<Re
map(mergeAll),
switchMap(github.createPullRequest),
switchMap(updateIssues(jira, messenger)),
tap(data => messenger.emit(`Pull request created: ${data.pullRequest.url}`, Emoji.LINK)),
tap((data) => messenger.emit(`Pull request created: ${data.pullRequest.url}`, Emoji.LINK)),
);
};
12 changes: 6 additions & 6 deletions src/commands/Start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const getOrCreateIssue = (
has('id'),
compose(
tracker.getIssue,
rTap(id => {
rTap((id) => {
messenger.emit(`Getting ${id} from Jira`, Emoji.BUG);
}),
prop('id'),
Expand Down Expand Up @@ -79,7 +79,7 @@ const createBranch = (
): ((data: IssueAndStartData) => Promise<void>) =>
compose(
git.createBranchAndStashChanges,
rTap(name => {
rTap((name) => {
messenger.emit(`Creating branch ${name}`, Emoji.TADA);
}),
git.getBranchNameForIssue,
Expand All @@ -103,17 +103,17 @@ const maybeAskUserToSelectIssue = (tracker: Tracker, messenger: Messenger) => (
{
allowTextSearch: true,
data: [issues],
getLabel: issue => `${issue.key} (${issue.type}) - ${issue.summary}`,
getLabel: (issue) => `${issue.key} (${issue.type}) - ${issue.summary}`,
getQuestion: () => 'What ticket would you like to start working on?',
getValue: issue => issue.key,
getValue: (issue) => issue.key,
limit: 15,
useDefaults: false,
},
messenger,
),
),
map(issues => issues[0]),
map(issue => ({ ...data, issue: { id: issue.key } })),
map((issues) => issues[0]),
map((issue) => ({ ...data, issue: { id: issue.key } })),
);
} else {
return of(data);
Expand Down
12 changes: 6 additions & 6 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ const messenger = new Messenger();
* @param args Args
*/
const askForConfigs = (msg: Messenger, args: FotingoArguments): Observable<FotingoArguments> =>
from(requiredConfigs.filter(cfg => R.path(cfg.path, args.config) === undefined)).pipe(
concatMap(requiredConfig =>
msg.request(requiredConfig.request).pipe(map(value => [requiredConfig.path, value])),
from(requiredConfigs.filter((cfg) => R.path(cfg.path, args.config) === undefined)).pipe(
concatMap((requiredConfig) =>
msg.request(requiredConfig.request).pipe(map((value) => [requiredConfig.path, value])),
),
reduce<[string[], string], Partial<Config>>((acc, val) => {
return R.set(R.lensPath(val[0]), val[1], acc);
}, {}),
map(write),
map(data => ({ config: data })),
map(d => R.mergeDeepRight(args, d) as FotingoArguments),
map((data) => ({ config: data })),
map((d) => R.mergeDeepRight(args, d) as FotingoArguments),
);

/**
Expand All @@ -66,7 +66,7 @@ export const run: (args: FotingoArguments) => void = R.ifElse(
args,
cmd: () =>
askForConfigs(messenger, args).pipe(
switchMap(augmentedArgs => cmd(augmentedArgs, messenger)),
switchMap((augmentedArgs) => cmd(augmentedArgs, messenger)),
),
isDebugging: process.env.DEBUG !== undefined,
messenger,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const getLocalChangesInformation = (issueTracker: Tracker, messenger: Mes
of(branchInfo),
merge(
...allIssues
.filter(issue => issueTracker.isValidIssueName(issue))
.map(issue =>
.filter((issue) => issueTracker.isValidIssueName(issue))
.map((issue) =>
issueTracker.getIssue(issue).pipe(
catchError((e: JiraError) => {
if (e.code === 404) {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const read: () => Config = () =>
* Write some partial configuration into the closest found config file
* @param config Partial configuration
*/
export const write: (data: Partial<Config>) => Partial<Config> = data => {
export const write: (data: Partial<Config>) => Partial<Config> = (data) => {
const search = cosmiconfig('fotingo').search() || { filepath: undefined, config: {} };
const mergedConfigs = R.mergeDeepLeft(data, search.config);
writeFileSync(
Expand Down
2 changes: 1 addition & 1 deletion src/enhanceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function enhanceConfig(config: Config): Promise<Config> {
const rootDir = await git.getRootDir();
const prTemplate = await getFileContent('PULL_REQUEST_TEMPLATE.md', rootDir, ['.', '.github']);
return git.getRemote(configWithDefaults.git.remote).then(
remote =>
(remote) =>
mergeDeepLeft(
{
github: {
Expand Down
6 changes: 1 addition & 5 deletions src/fotingo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import { enhanceConfig } from 'src/enhanceConfig';
import { commandDir } from 'yargs';

enhanceConfig(read()).then((config: Config) => {
const program = commandDir('./cli')
.demandCommand()
.config({ config })
.completion()
.help();
const program = commandDir('./cli').demandCommand().config({ config }).completion().help();

compose(run, prop('argv'))(program);
});
6 changes: 2 additions & 4 deletions src/git/Branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ const getTemplateKeysMatchIndexMap = (regex: string): { [S in TemplateKey]: numb
}),
{},
);
const orderedValues = Object.values(indexMap)
.sort(subtract)
.filter(lt(-1));
return mapObjIndexed(i => 1 + orderedValues.indexOf(i), indexMap) as {
const orderedValues = Object.values(indexMap).sort(subtract).filter(lt(-1));
return mapObjIndexed((i) => 1 + orderedValues.indexOf(i), indexMap) as {
[S in TemplateKey]: number;
};
};
Expand Down
22 changes: 11 additions & 11 deletions src/git/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ export class Git {
public createBranchAndStashChanges(branchName: string): Promise<void> {
return this.fetch()
.then(() => this.doesBranchExist(branchName))
.then(exists => {
.then((exists) => {
if (exists) {
// TODO Imrpove this error
throw new Error('There is already a branch for the issue');
}
})
.then(() => this.maybeStashChanges())
.then(() => this.findBaseBranch())
.then(baseBranch => this.getLatestCommit(baseBranch).then(log => log.latest.hash))
.then(lastCommitHash => this.git.checkoutBranch(branchName, lastCommitHash))
.then((baseBranch) => this.getLatestCommit(baseBranch).then((log) => log.latest.hash))
.then((lastCommitHash) => this.git.checkoutBranch(branchName, lastCommitHash))
.catch(this.mapAndThrowError);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ export class Git {
public async doesBranchExist(branchName: string): Promise<boolean> {
return this.git
.branchLocal()
.then((branches: BranchSummary) => branches.all.some(branch => branch === branchName));
.then((branches: BranchSummary) => branches.all.some((branch) => branch === branchName));
}

/**
Expand All @@ -205,13 +205,13 @@ export class Git {
public async findBaseBranch(removePrefix = false): Promise<string> {
const branchPrefix = `remotes/${this.config.remote}`;
const branches: Array<{ name: string }> = ((await this.git.branch(['-a'])) as BranchSummary).all
.filter(b => b.startsWith(branchPrefix))
.filter((b) => b.startsWith(branchPrefix))
.map((branchName: string) => ({ name: branchName }));

const matches = findMatches(
{
checkForExactMatchFirst: true,
cleanData: item => item.replace(`${branchPrefix}/`, ''),
cleanData: (item) => item.replace(`${branchPrefix}/`, ''),
data: branches,
fields: ['name'],
},
Expand All @@ -227,10 +227,10 @@ export class Git {
const baseBranch = await maybeAskUserToSelectMatches(
{
data: matches,
getLabel: branch => branch.name.replace(`${branchPrefix}/`, ''),
getQuestion: item =>
getLabel: (branch) => branch.name.replace(`${branchPrefix}/`, ''),
getQuestion: (item) =>
`We couldn't find a unique match for the base branch "${item}", which one best matches?`,
getValue: branch => branch.name,
getValue: (branch) => branch.name,
options: [this.config.baseBranch],
useDefaults: false,
},
Expand All @@ -254,7 +254,7 @@ export class Git {
),
[
compose(
ifElse(isNil, always([]), key => [{ raw: `#${key}`, issue: key }]),
ifElse(isNil, always([]), (key) => [{ raw: `#${key}`, issue: key }]),
nthArg(0),
),
compose(
Expand Down Expand Up @@ -316,7 +316,7 @@ export class Git {
* be auto generated by fotingo
*/
private maybeStashChanges(): Promise<void> {
return this.status().then(st => {
return this.status().then((st) => {
if (st.files.length > 0) {
return this.git
.stash(['save', '--include-untracked', 'Auto generated by fotingo'])
Expand Down
26 changes: 13 additions & 13 deletions src/git/Github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ export class Github implements Remote {
const foundLabels = findMatches({ fields: ['name'], data: ghLabels }, labels);

const foundReviewers = reviewers.map(
reviewer =>
(reviewer) =>
findMatches({ fields: ['login', 'name', 'email'], data: ghReviewers }, [reviewer])[0],
);

const selectedReviewers = await maybeAskUserToSelectMatches(
{
data: foundReviewers,
getLabel: r => {
getLabel: (r) => {
if (r.name) {
return `${r.name} (${r.login})`;
}
return r.login;
},
getQuestion: match =>
getQuestion: (match) =>
`We couldn't find a unique match for reviewer "${match}", which one best matches?`,
getValue: r => r.login,
getValue: (r) => r.login,
options: reviewers,
useDefaults,
},
Expand All @@ -115,10 +115,10 @@ export class Github implements Remote {
const selectedLabels = await maybeAskUserToSelectMatches(
{
data: foundLabels,
getLabel: l => `${l.name}`,
getQuestion: match =>
getLabel: (l) => `${l.name}`,
getQuestion: (match) =>
`We couldn't find a unique match for labels "${match}", which one best matches?`,
getValue: l => String(l.id),
getValue: (l) => String(l.id),
options: labels,
useDefaults,
},
Expand Down Expand Up @@ -278,7 +278,7 @@ export class Github implements Remote {
repo: this.config.repo,
title: compose<string, string[], string>(head, split('\n'))(content),
})
.then(response => response.data);
.then((response) => response.data);
}

/**
Expand All @@ -298,7 +298,7 @@ export class Github implements Remote {
repo: this.config.repo,
reviewers: map(prop('login'), reviewers),
})
.then(response => response.data);
.then((response) => response.data);
}

/**
Expand All @@ -313,7 +313,7 @@ export class Github implements Remote {
return this.api.issues.addLabels({
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: pullRequest.number,
labels: labels.map(label => label.name),
labels: labels.map((label) => label.name),
owner: this.config.owner,
repo: this.config.repo,
});
Expand Down Expand Up @@ -357,7 +357,7 @@ export class Github implements Remote {
owner: this.config.owner,
repo: this.config.repo,
})
.then(response => response.data.length > 0),
.then((response) => response.data.length > 0),
'Checking if there is a PR for %s',
branchName,
);
Expand All @@ -375,11 +375,11 @@ export class Github implements Remote {
data: mapObjIndexed(escapeHtml, {
[PR_TEMPLATE_KEYS.CHANGES]: branchInfo.commits
.reverse()
.map(c => `* ${c.header}`)
.map((c) => `* ${c.header}`)
.join('\n'),
[PR_TEMPLATE_KEYS.FIXED_ISSUES]:
issues.length > 0
? rConcat('Fixes ', issues.map(issue => `[#${issue.key}](${issue.url})`).join(', '))
? rConcat('Fixes ', issues.map((issue) => `[#${issue.key}](${issue.url})`).join(', '))
: '',
[PR_TEMPLATE_KEYS.BRANCH_NAME]: branchInfo.name,
[PR_TEMPLATE_KEYS.DESCRIPTION]: data.description,
Expand Down
4 changes: 2 additions & 2 deletions src/io/cacheable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export function cacheable({
);
}

const cachedFn: PromiseFunction = async function(...args) {
const cachedFn: PromiseFunction = async function (...args) {
if (isCacheDisabled) {
return method.call(this, ...args);
}
const prefix = getPrefix ? getPrefix.call(this, ...args) : '';
const keyArgs = args.length > 0 ? `_${args.map(val => JSON.stringify(val)).join('_')}` : '';
const keyArgs = args.length > 0 ? `_${args.map((val) => JSON.stringify(val)).join('_')}` : '';
const key = `${prefix}${target.constructor.name}_${String(propertyKey)}${keyArgs}`;
const cachedValue = await keyv.get(key);
if (cachedValue) {
Expand Down
6 changes: 3 additions & 3 deletions src/io/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export async function getFileContent(
): Promise<string | undefined> {
const data = await Promise.all(
folders
.map(folder => resolve(root, folder, name))
.map(p => readFile(p, 'utf-8').catch(() => undefined)),
.map((folder) => resolve(root, folder, name))
.map((p) => readFile(p, 'utf-8').catch(() => undefined)),
);
return data.filter(e => e !== undefined)[0];
return data.filter((e) => e !== undefined)[0];
}
4 changes: 2 additions & 2 deletions src/io/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function maybeAskUserToSelectMatches<T>(
.request(getQuestion(options[i]), {
allowTextSearch,
options: uniqBy<T, string>(getValue, limit > 0 ? take(limit, matches) : matches).map(
r => ({
(r) => ({
label: getLabel(r),
value: getValue(r),
}),
Expand All @@ -61,7 +61,7 @@ export function maybeAskUserToSelectMatches<T>(
.toPromise()
// We know the user selected an option
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.then((option: string) => matches.find(r => String(getValue(r)) === String(option))!)
.then((option: string) => matches.find((r) => String(getValue(r)) === String(option))!)
);
}),
);
Expand Down

0 comments on commit 2350080

Please sign in to comment.