Created
March 7, 2018 13:35
-
-
Save jessitron/e1a3fc188b63b5baf0817114731ea8cf to your computer and use it in GitHub Desktop.
Atomist command to find out who is reviewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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