Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Add extra samples
Browse files Browse the repository at this point in the history
Fixes #8
Fixes #7
Fixes #5
  • Loading branch information
Lieven Doclo committed Jun 18, 2019
1 parent 9c72c66 commit 1f4ec18
Show file tree
Hide file tree
Showing 16 changed files with 52,094 additions and 15 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Here is a list of all the samples in this repository:
<!---atomist:sample=start--->
|Name|Description|Tags|
|----|-----------|----|
|[`lib/command/graphqlQuery.ts`](lib/command/graphqlQuery.ts)|Demonstrates executing a custom GraphQL query|command, parameters, graphql|
|[`lib/command/helloWorld.ts`](lib/command/helloWorld.ts)|Demonstrates a "hello world" command handler|command|
|[`lib/command/menu.ts`](lib/command/menu.ts)|Demonstrates using menus in chat|command, parameters|
|[`lib/command/parameters.ts`](lib/command/parameters.ts)|Demonstrates a command handler with parameters|command, parameters|
Expand All @@ -32,6 +33,8 @@ Here is a list of all the samples in this repository:
|[`lib/generate/springBoot.ts`](lib/generate/springBoot.ts)|SDM to create a new Spring Boot project showing promptFor from generators|generator, sdm|
|[`lib/goal/addLicenseAutofix.ts`](lib/goal/addLicenseAutofix.ts)|Shows how to use the Autofix goal|autofix, goal|
|[`lib/goal/firstGoal.ts`](lib/goal/firstGoal.ts)|Demonstrates how to create a first custom goal|goal|
|[`lib/goal/goalWithCustomFulfillment.ts`](lib/goal/goalWithBuiltInFulfillment.ts)|Demonstrates how to create a custom goal with a fulfillment that is configured inside the goal|goal|
|[`lib/goal/goalWithCustomFulfillment.ts`](lib/goal/goalWithCustomFulfillment.ts)|Demonstrates how to create a custom goal with a fulfillment that is configured outside the goal|goal|
|[`lib/sdm/dotnetCore.ts`](lib/sdm/dotnetCore.ts)|SDM to create and build .NET Core projects|dotnet-core, generator, sdm|
|[`lib/sdm/jenkinsJob.ts`](lib/sdm/jenkinsJob.ts)|SDM to demonstrate how to run and converge Jenkins jobs|jenkins, maven, sdm|
|[`lib/sdm/maven.ts`](lib/sdm/maven.ts)|SDM to create and build Maven projects|generator, maven, sdm|
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Please start an SDM sample by selecting one of the files in the menu below.`, {
cfg.name = `@atomist/samples-${name.toLowerCase()}`;

// The sample SDM startup does not support cluster mode
cfg.cluster.enabled = false;
_.set(cfg, "cluster.enabled", false);

return cfg;
}
Expand Down
73 changes: 73 additions & 0 deletions lib/command/graphqlQuery.ts
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);

});
72 changes: 72 additions & 0 deletions lib/goal/goalWithBuiltInFulfillment.ts
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,
},
};
});
72 changes: 72 additions & 0 deletions lib/goal/goalWithCustomFulfillment.ts
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,
},
};
});
8 changes: 8 additions & 0 deletions lib/graphql/query/BuildStatusBySha.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query BuildStatusBySha($sha: String!) {
Commit(sha: $sha) {
builds {
status
timestamp
}
}
}
Loading

0 comments on commit 1f4ec18

Please sign in to comment.