This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lieven Doclo
committed
Jun 18, 2019
1 parent
9c72c66
commit 1f4ec18
Showing
16 changed files
with
52,094 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright © 2019 Atomist, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Atomist SDM Sample | ||
* @description Demonstrates executing a custom GraphQL query | ||
* @tag command,parameters,graphql | ||
* @instructions <p>Now that the SDM is up and running, start the sample command handler | ||
* from chat or web-app by typing "@atomist start".</p> | ||
*/ | ||
|
||
import { QueryNoCacheOptions } from "@atomist/automation-client"; | ||
import { CommandHandlerRegistration } from "@atomist/sdm"; | ||
import { configure } from "@atomist/sdm-core"; | ||
import * as _ from "lodash"; | ||
import { BuildStatusBySha } from "../typings/types"; | ||
|
||
/** | ||
* Command handler that asks to enter a SHA and which will return the build status of that SHA | ||
*/ | ||
const BuildStatusForShaCommand: CommandHandlerRegistration = { | ||
name: "BuildStatusForSha", | ||
intent: "start", | ||
listener: async ci => { | ||
|
||
const params = await ci.promptFor<{ sha: string }>({ | ||
sha: { | ||
description: "enter a SHA", | ||
}, | ||
}); | ||
|
||
const sha = params.sha; | ||
// The query for this can be found in lib/graphql/query/BuildStatusBySha.graphql. The build process will generate types | ||
// for this query, so that you have type safety. | ||
const builds = await ci.context.graphClient.query<BuildStatusBySha.Query, BuildStatusBySha.Variables>({ | ||
name: "BuildStatusBySha", | ||
variables: { | ||
sha, | ||
}, | ||
options: QueryNoCacheOptions, | ||
}); | ||
|
||
const status = _.get(builds, "Commit[0].builds[0].status"); | ||
|
||
if (!!status) { | ||
await ci.addressChannels(`The status of the build is ${status}`); | ||
} else { | ||
await ci.addressChannels(`The SHA ${sha} does not have a build status`); | ||
} | ||
|
||
}, | ||
}; | ||
|
||
/** | ||
* Install the command handler into the SDM | ||
*/ | ||
export const configuration = configure(async sdm => { | ||
sdm.addCommand(BuildStatusForShaCommand); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright © 2019 Atomist, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
AnyPush, | ||
DefaultGoalNameGenerator, | ||
GoalInvocation, | ||
GoalWithFulfillment, | ||
} from "@atomist/sdm"; | ||
import { configure } from "@atomist/sdm-core"; | ||
import * as _ from "lodash"; | ||
|
||
/** | ||
* Atomist SDM Sample | ||
* @description Demonstrates how to create a custom goal with a fulfillment that is configured inside the goal | ||
* @tag goal | ||
* @instructions <p>Now that the SDM is up and running, make a commit to a repository | ||
* that has an Atomist webhook configured. You can observe the goal | ||
* from chat or https://app.atomist.com.</p> | ||
*/ | ||
export class MessageGoal extends GoalWithFulfillment { | ||
constructor() { | ||
super({uniqueName: DefaultGoalNameGenerator.generateName("messageGoal"), displayName: "Message contributor"}); | ||
this.addFulfillment({ | ||
name: "execute", | ||
goalExecutor: MessageGoal.executeGoal, | ||
}); | ||
} | ||
|
||
private static async executeGoal(gi: GoalInvocation): Promise<void> { | ||
const { goalEvent, context, progressLog } = gi; | ||
|
||
// Carefully get the screenName of the user authoring this push | ||
const screenName = _.get(goalEvent, "push.after.author.person.chatId.screenName"); | ||
|
||
// When Atomist correlated the Git author to a chat identity, this will send a thank you note to the author | ||
if (!!screenName) { | ||
|
||
// Writing a log message into the progress log which is linked from the goal in chat or web | ||
progressLog.write(`Sending thank you note to user ${screenName}`); | ||
|
||
await context.messageClient.addressUsers( | ||
":clap: Many thanks for your contribution! :tada:", | ||
screenName, | ||
{ id: "thank_you" }); // Using the same message id will make sure the user only sees one thank you note | ||
} | ||
} | ||
} | ||
|
||
export const configuration = configure(async () => { | ||
const messageGoal = new MessageGoal(); | ||
return { | ||
// Define a PushRule with name 'thank you' that schedules the messageGoal for any push | ||
thank_you: { | ||
test: AnyPush, | ||
goals: messageGoal, | ||
}, | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright © 2019 Atomist, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
AnyPush, | ||
DefaultGoalNameGenerator, | ||
GoalWithFulfillment, | ||
} from "@atomist/sdm"; | ||
import { configure } from "@atomist/sdm-core"; | ||
import * as _ from "lodash"; | ||
|
||
/** | ||
* Atomist SDM Sample | ||
* @description Demonstrates how to create a custom goal with a fulfillment that is configured outside the goal | ||
* @tag goal | ||
* @instructions <p>Now that the SDM is up and running, make a commit to a repository | ||
* that has an Atomist webhook configured. You can observe the goal | ||
* from chat or https://app.atomist.com.</p> | ||
*/ | ||
|
||
export class MessageGoal extends GoalWithFulfillment { | ||
constructor() { | ||
super({uniqueName: DefaultGoalNameGenerator.generateName("messageGoal"), displayName: "Message contributor"}); | ||
} | ||
} | ||
|
||
export const configuration = configure(async () => { | ||
|
||
const messageGoal = new MessageGoal(); | ||
messageGoal.with({ | ||
name: "execute", | ||
goalExecutor: async gi => { | ||
const { goalEvent, context, progressLog } = gi; | ||
|
||
// Carefully get the screenName of the user authoring this push | ||
const screenName = _.get(goalEvent, "push.after.author.person.chatId.screenName"); | ||
|
||
// When Atomist correlated the Git author to a chat identity, this will send a thank you note to the author | ||
if (!!screenName) { | ||
|
||
// Writing a log message into the progress log which is linked from the goal in chat or web | ||
progressLog.write(`Sending thank you note to user ${screenName}`); | ||
|
||
await context.messageClient.addressUsers( | ||
":clap: Many thanks for your contribution! :tada:", | ||
screenName, | ||
{ id: "thank_you" }); // Using the same message id will make sure the user only sees one thank you note | ||
} | ||
}, | ||
}); | ||
|
||
return { | ||
// Define a PushRule with name 'thank you' that schedules the messageGoal for any push | ||
thank_you: { | ||
test: AnyPush, | ||
goals: messageGoal, | ||
}, | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query BuildStatusBySha($sha: String!) { | ||
Commit(sha: $sha) { | ||
builds { | ||
status | ||
timestamp | ||
} | ||
} | ||
} |
Oops, something went wrong.