1 | # @atomist/automation-seed
|
2 |
|
3 | [![Build Status](https://travis-ci.org/atomist/automation-seed-ts.svg?branch=master)](https://travis-ci.org/atomist/automation-seed-ts)
|
4 |
|
5 | This repository contains examples demonstrating use of
|
6 | the [Atomist][atomist] API. You will find examples illustrating:
|
7 |
|
8 | - Creating bot commands using _command handlers_
|
9 | - Responding to DevOps events, e.g., commits pushed to a repository,
|
10 | using _event handlers_
|
11 |
|
12 | These example use the [`@atomist/automation-client`][client] node
|
13 | module to implement a local client that connects to the Atomist API.
|
14 |
|
15 | [client]: https://github.com/atomist/automation-client-ts (@atomist/automation-client Node Module)
|
16 |
|
17 | ## Prerequisites
|
18 |
|
19 | ### Access to Atomist testing environment
|
20 |
|
21 | To get access to this preview, please reach out to members of Atomist
|
22 | in the `#support` channel of [atomist-community Slack team][slack].
|
23 |
|
24 | You'll receive an invitation to a [Slack team][play-slack]
|
25 | and [GitHub organization][play-gh] that can be used to explore this
|
26 | new approach to writing and running automations.
|
27 |
|
28 | [play-slack]: https://atomist-playground.slack.com (Atomist Playground Slack)
|
29 | [play-gh]: https://github.com/atomist-playground (Atomist Playground GitHub Organization)
|
30 |
|
31 | ### Node.js
|
32 |
|
33 | You will need to have [Node.js][node] installed. To verify that the
|
34 | right versions are installed, please run:
|
35 |
|
36 | ```
|
37 | $ node -v
|
38 | v8.4.0
|
39 | $ npm -v
|
40 | 5.4.1
|
41 | ```
|
42 |
|
43 | [node]: https://nodejs.org/ (Node.js)
|
44 |
|
45 | ### Cloning the repository and installing dependencies
|
46 |
|
47 | To get started run the following commands:
|
48 |
|
49 | ```
|
50 | $ git clone git@github.com:atomist/automation-seed-ts.git
|
51 | $ cd automation-seed-ts
|
52 | $ npm install
|
53 | ```
|
54 |
|
55 | ### Configuring your environment
|
56 |
|
57 | For the client to connect and authenticate to the Atomist API,
|
58 | a [GitHub personal access token][token] with `read:org` scope is
|
59 | required. Once you have obtained the GitHub personal access token,
|
60 | make it available to the client by exporting it into an environment
|
61 | variable:
|
62 |
|
63 | ```
|
64 | $ export GITHUB_TOKEN=<your token goes here>
|
65 | ```
|
66 |
|
67 | Alternatively you can also place the token in `src/atomist.config.ts`.
|
68 | Replace
|
69 |
|
70 | ```typescript
|
71 | const token = process.env.GITHUB_TOKEN;
|
72 | ```
|
73 |
|
74 | with
|
75 |
|
76 | ```typescript
|
77 | const token = "your token goes here";
|
78 | ```
|
79 |
|
80 | *If you add the token to the `atomist.config.ts`, please do **not**
|
81 | commit the file and push it to GitHub.com.*
|
82 |
|
83 | [token]: https://github.com/settings/tokens (GitHub Personal Access Tokens)
|
84 |
|
85 | The Atomist API will only allows members of the GitHub team
|
86 | `atomist-automation` to authenticate and register a new client. If
|
87 | you followed the instructions above and have been invited to
|
88 | the [atomist-playground][play-gh] GitHub organization, you will have
|
89 | been added to this team in that organization. If you are trying to
|
90 | run these automations in your own Slack team and GitHub organization,
|
91 | you will have to create a team in your GitHub organization named
|
92 | `atomist-automation` and add the users who want to create and register
|
93 | automations to it.
|
94 |
|
95 | ## Starting up the automation-client
|
96 |
|
97 | To start the client, run the following command:
|
98 |
|
99 | ```
|
100 | $ npm run start
|
101 | ```
|
102 |
|
103 | ## Invoking a command handler from Slack
|
104 |
|
105 | This project contains the code to create and respond to a simple
|
106 | `hello world` bot command. The code that defines the bot command and
|
107 | implements responding to the command, i.e., the _command handler_, can
|
108 | be found in [`HelloWorld.ts`][hello]. Once you have your local
|
109 | automation client running (the previous step in this guide), you can
|
110 | invoke the command handler by sending the Atomist bot the command in
|
111 | the `#general` channel of the [atomist-playground Slack team][play-slack]:
|
112 |
|
113 | ```
|
114 | @atomist hello world
|
115 | ```
|
116 |
|
117 | Once you've submitted the command in Slack, you'll see the incoming
|
118 | and outgoing messages show up in the logs of your locally running
|
119 | automation-client. Ultimately, you should see the response from the
|
120 | bot in Slack.
|
121 |
|
122 | [hello]: https://github.com/atomist/automation-seed-ts/blob/master/src/commands/HelloWorld.ts (HelloWorld Command Handler)
|
123 |
|
124 | Feel free to modify the code in the `HelloWorld` command handler,
|
125 | restart your local automation client, and see what happens!
|
126 |
|
127 | ## Triggering an event handler
|
128 |
|
129 | While command handlers respond to commands you send the Atomist bot,
|
130 | _event handlers_ take action when different types of events occur in
|
131 | your development and operations environment. Some examples of events
|
132 | are commits pushed to a repo, or a CI build that fails, or an instance
|
133 | of a running service that becomes unhealthy. Example responses to those
|
134 | events are showing the commits in a Slack message, automatically
|
135 | restarting the build, and triggering a PagerDuty alert, respectively.
|
136 |
|
137 | The sample event handler in this project, [NotifyOnPush][nop-handler],
|
138 | will notice when someone pushes new commits to a repository in the
|
139 | GitHub organization and send a notice of that push to all Slack
|
140 | channels associated with that repository.
|
141 |
|
142 | If you have followed the instructions above and are running these
|
143 | automations against the atomist-playground Slack team and GitHub
|
144 | organization, go ahead and edit the [notify-on-push][nop-repo]
|
145 | repository by adding some test to its [README][nop-readme]. Once you
|
146 | have saved your changes, you should see that event appear in the
|
147 | console logs of your locally running automation client, followed by a
|
148 | log of the actions the event handler is taking. Once those actions
|
149 | are complete, you should see a new message in the
|
150 | [`#notify-on-push`][nop-channel] channel in the atomist-playground
|
151 | Slack team.
|
152 |
|
153 | [nop-handler]: https://github.com/atomist/automation-seed-ts/blob/master/src/events/NotifyOnPush.ts (Atomist NotifyOnPush Event Handler)
|
154 | [nop-repo]: https://github.com/atomist-playground/notify-on-push (Atomist NotifyOnPush Repository)
|
155 | [nop-readme]: https://github.com/atomist-playground/notify-on-push/edit/master/README.md (Edit NotifyOnPush README)
|
156 | [nop-channel]: https://atomist-playground.slack.com/messages/C7GNF6743/ (NotifyOnPush Slack Channel)
|
157 |
|
158 | ## Dashboard and GraphQL data explorer
|
159 |
|
160 | When the automation client has successfully established a connection
|
161 | to the Atomist API server, the Dashboard (work-in-progress) and
|
162 | GraphQL data explorer will be available.
|
163 |
|
164 | * Dashboard: http://localhost:2866
|
165 | * GraphQL Data Explorer: http://localhost:2866/graphql
|
166 |
|
167 | ## Support
|
168 |
|
169 | General support questions should be discussed in the `#support`
|
170 | channel in our community Slack team
|
171 | at [atomist-community.slack.com][slack].
|
172 |
|
173 | If you find a problem, please create an [issue][].
|
174 |
|
175 | [issue]: https://github.com/atomist/automation-seed-ts/issues
|
176 |
|
177 | ## Development
|
178 |
|
179 | You will need to install [node][] to build and test this project.
|
180 |
|
181 | ### Build and Test
|
182 |
|
183 | Command | Reason
|
184 | ------- | ------
|
185 | `npm install` | to install all the required packages
|
186 | `npm run start` | to start the Atomist automation client
|
187 | `npm run lint` | to run tslint against the TypeScript
|
188 | `npm run compile` | to compile all TypeScript into JavaScript
|
189 | `npm test` | to run tests and ensure everything is working
|
190 | `npm run autotest` | run tests continuously (you may also need to run `tsc -w`)
|
191 | `npm run clean` | remove stray compiled JavaScript files and build directory
|
192 |
|
193 | ### Release
|
194 |
|
195 | To create a new release of the project, simply push a tag of the form
|
196 | `M.N.P` where `M`, `N`, and `P` are integers that form the next
|
197 | appropriate [semantic version][semver] for release. The version in
|
198 | the package.json is replaced by the build and is totally ignored! For
|
199 | example:
|
200 |
|
201 | [semver]: http://semver.org
|
202 |
|
203 | ```
|
204 | $ git tag -a 1.2.3
|
205 | $ git push --tags
|
206 | ```
|
207 |
|
208 | The Travis CI build (see badge at the top of this page) will publish
|
209 | the NPM module and automatically create a GitHub release using the tag
|
210 | name for the release and the comment provided on the annotated tag as
|
211 | the contents of the release notes.
|
212 |
|
213 | ---
|
214 |
|
215 | Created by [Atomist][atomist].
|
216 | Need Help? [Join our Slack team][slack].
|
217 |
|
218 | [atomist]: https://www.atomist.com/
|
219 | [slack]: https://join.atomist.com
|