Skip to content

Instantly share code, notes, and snippets.

@jessitron
Created March 7, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessitron/e1a3fc188b63b5baf0817114731ea8cf to your computer and use it in GitHub Desktop.
Save jessitron/e1a3fc188b63b5baf0817114731ea8cf to your computer and use it in GitHub Desktop.
Atomist command to find out who is reviewing
import { commandHandlerFrom } from "@atomist/automation-client/onCommand";
import { HandleCommand } from "@atomist/automation-client";
import { Parameters } from "@atomist/automation-client/decorators";
import * as _ from "lodash"
@Parameters()
export class WhoIsBusyParameters {
}
export const whoIsBusyCommand: HandleCommand<any> = commandHandlerFrom(
async (ctx) => {
await ctx.messageClient.respond("I hear you");
const result: any = await ctx.graphClient.executeQuery(`query K {
PullRequest {
number
repo @required {
owner name
}
reviewers @required {
login
person {
chatId
{
screenName
}
}
}
}
}
`);
const allReviewers = _.flatten(result.PullRequest.map(r => r.reviewers))
const reviewersByLogin = _.groupBy(allReviewers,(r: any) => _.get(r, "person.chatId.screenName", r.login));
const lines = Object.keys(reviewersByLogin).map(login =>
`${login} has ${reviewersByLogin[login].length} review in process`);
return ctx.messageClient.respond(lines.join("\n"))
}, WhoIsBusyParameters,
"WhoIsBusy", "Peter", "who is busy"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment