Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
ESLint fixes (#14)
Browse files Browse the repository at this point in the history
 * ESLint fixes

[atomist:generated]
[atomist-skill:atomist/eslint-skill]
    
Pull request auto merged:

* 1 approved review by @cdupuis
* 2 successful checks
  • Loading branch information
atomist[bot] authored Jul 17, 2020
1 parent e585f0a commit 542f332
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 398 deletions.
106 changes: 60 additions & 46 deletions lib/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,77 @@ import { EventContext, github, repository, secret } from "@atomist/skill";
import { PullRequest } from "./typings/types";

export interface GitHubCommentDetails {
apiUrl: string;
owner: string;
repo: string;
number: number;
id: number;
apiUrl: string;
owner: string;
repo: string;
number: number;
id: number;
}

export type PullRequestCommentCreator<T> = (
ctx: EventContext,
pr: PullRequest,
credential: secret.GitHubAppCredential | secret.GitHubCredential,
body: string,
ctx: EventContext,
pr: PullRequest,
credential: secret.GitHubAppCredential | secret.GitHubCredential,
body: string,
) => Promise<T>;
export type PullRequestCommentUpdater<T> = (
ctx: EventContext,
comment: T,
credential: secret.GitHubAppCredential | secret.GitHubCredential,
body: string,
ctx: EventContext,
comment: T,
credential: secret.GitHubAppCredential | secret.GitHubCredential,
body: string,
) => Promise<void>;

export const gitHubPullRequestCommentCreator: PullRequestCommentCreator<GitHubCommentDetails> = async (
ctx,
pr,
credential,
body,
ctx,
pr,
credential,
body,
) => {
const result = (
await github
.api(repository.gitHub({ owner: pr.repo.owner, repo: pr.repo.name, credential }))
.issues.createComment({
owner: pr.repo.owner,
repo: pr.repo.name,
issue_number: pr.number,
body,
})
).data;
await ctx.audit.log(body);
return {
apiUrl: pr.repo.org.provider.apiUrl,
owner: pr.repo.owner,
repo: pr.repo.name,
number: pr.number,
id: result.id,
};
const result = (
await github
.api(
repository.gitHub({
owner: pr.repo.owner,
repo: pr.repo.name,
credential,
}),
)
.issues.createComment({
owner: pr.repo.owner,
repo: pr.repo.name,
issue_number: pr.number,
body,
})
).data;
await ctx.audit.log(body);
return {
apiUrl: pr.repo.org.provider.apiUrl,
owner: pr.repo.owner,
repo: pr.repo.name,
number: pr.number,
id: result.id,
};
};

export const gitHubPullRequestCommentUpdater: PullRequestCommentUpdater<GitHubCommentDetails> = async (
ctx,
comment,
credential,
body,
ctx,
comment,
credential,
body,
) => {
await github.api(repository.gitHub({ owner: comment.owner, repo: comment.repo, credential })).issues.updateComment({
owner: comment.owner,
repo: comment.repo,
comment_id: comment.id,
body,
});
await ctx.audit.log(body);
await github
.api(
repository.gitHub({
owner: comment.owner,
repo: comment.repo,
credential,
}),
)
.issues.updateComment({
owner: comment.owner,
repo: comment.repo,
comment_id: comment.id,
body,
});
await ctx.audit.log(body);
};
2 changes: 1 addition & 1 deletion lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

export interface RebaseConfiguration {
strategy?: "ours" | "theirs";
strategy?: "ours" | "theirs";
}
58 changes: 35 additions & 23 deletions lib/events/convergePullRequestAutoRebaseLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,47 @@
*/

import { EventHandler, secret, repository, github } from "@atomist/skill";
import { ConvergePullRequestAutoRebaseLabelsSubscription, PullRequestAction } from "../typings/types";
import {
ConvergePullRequestAutoRebaseLabelsSubscription,
PullRequestAction,
} from "../typings/types";

export const AutoRebaseOnPushLabel = "auto-rebase:on-push";

export const handler: EventHandler<ConvergePullRequestAutoRebaseLabelsSubscription> = async ctx => {
const pr = ctx.data.PullRequest[0];
const pr = ctx.data.PullRequest[0];

if (pr.action !== PullRequestAction.Opened) {
await ctx.audit.log(
`Pull request ${pr.repo.owner}/${pr.repo.name}#${pr.number} action not opened. Ignoring...`,
);
if (pr.action !== PullRequestAction.Opened) {
await ctx.audit.log(
`Pull request ${pr.repo.owner}/${pr.repo.name}#${pr.number} action not opened. Ignoring...`,
);

return {
visibility: "hidden",
code: 0,
reason: `Pull request [${pr.repo.owner}/${pr.repo.name}#${pr.number}](${pr.url}) action not opened. Ignoring...`,
};
}
return {
visibility: "hidden",
code: 0,
reason: `Pull request [${pr.repo.owner}/${pr.repo.name}#${pr.number}](${pr.url}) action not opened. Ignoring...`,
};
}

const repo = ctx.data.PullRequest[0].repo;
const { owner, name } = repo;
const credential = await ctx.credential.resolve(secret.gitHubAppToken({ owner, repo: name }));
const repo = ctx.data.PullRequest[0].repo;
const { owner, name } = repo;
const credential = await ctx.credential.resolve(
secret.gitHubAppToken({ owner, repo: name }),
);

const id = repository.gitHub({ owner, repo: name, credential });
await ctx.audit.log(`Converging auto-rebase label '${AutoRebaseOnPushLabel}'`);
await github.convergeLabel(id, AutoRebaseOnPushLabel, "0E8A16", "Auto-rebase pull request branch");
await ctx.audit.log(`Converged auto-rebase label 'AutoRebaseOnPushLabel'`);
return {
code: 0,
reason: `Converged auto-rebase label for [${repo.owner}/${repo.name}](${repo.url})`,
};
const id = repository.gitHub({ owner, repo: name, credential });
await ctx.audit.log(
`Converging auto-rebase label '${AutoRebaseOnPushLabel}'`,
);
await github.convergeLabel(
id,
AutoRebaseOnPushLabel,
"0E8A16",
"Auto-rebase pull request branch",
);
await ctx.audit.log(`Converged auto-rebase label 'AutoRebaseOnPushLabel'`);
return {
code: 0,
reason: `Converged auto-rebase label for [${repo.owner}/${repo.name}](${repo.url})`,
};
};
Loading

0 comments on commit 542f332

Please sign in to comment.