UNPKG

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