Skip to content

Commit 79b1ece

Browse files
authored
Add Engineering Data Platform specs (#63)
1 parent 4e14526 commit 79b1ece

File tree

730 files changed

+28683
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

730 files changed

+28683
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
1-
Copyright (c) 2015 Code Climate, Inc.
2-
3-
Permission is hereby granted, free of charge, to any person obtaining a copy
4-
of this software and associated documentation files (the "Software"), to deal
5-
in the Software without restriction, including without limitation the rights
6-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
copies of the Software, and to permit persons to whom the Software is
8-
furnished to do so, subject to the following conditions:
9-
10-
The above copyright notice and this permission notice shall be included in
11-
all copies or substantial portions of the Software.
12-
13-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
THE SOFTWARE.
20-
21-
----------------------------------------------------------------
22-
23-
###### _This repo incorporates text from the App Container Specification, which is licensed as follows:_
24-
25-
Apache License
1+
Apache License
262
Version 2.0, January 2004
273
http://www.apache.org/licenses/
284

@@ -202,15 +178,15 @@ Apache License
202178
APPENDIX: How to apply the Apache License to your work.
203179

204180
To apply the Apache License to your work, attach the following
205-
boilerplate notice, with the fields enclosed by brackets "{}"
181+
boilerplate notice, with the fields enclosed by brackets "[]"
206182
replaced with your own identifying information. (Don't include
207183
the brackets!) The text should be enclosed in the appropriate
208184
comment syntax for the file format. We also recommend that a
209185
file or class name and description of purpose be included on the
210186
same "printed page" as the copyright notice for easier
211187
identification within third-party archives.
212188

213-
Copyright {yyyy} {name of copyright owner}
189+
Copyright [yyyy] [name of copyright owner]
214190

215191
Licensed under the Apache License, Version 2.0 (the "License");
216192
you may not use this file except in compliance with the License.
File renamed without changes.

docs/connectors/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Code Climate Connectors
2+
3+
## Table of Contents
4+
5+
1. [Getting Started](getting_started.md)
6+
2. [Concepts](concepts.md)
7+
3. [Data Consumer's Guide](data_consumer_guide.md)
8+
4. [Connector Developer's Guide](connector_developer_guide.md)
9+
5. [Reference](reference.md)

docs/connectors/concepts.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Concepts
2+
3+
## Components
4+
5+
### Configuration
6+
7+
A Configuration for a Connector must be representable as a JSON object. When given to the Connector, it is a JavaScript `Map`. The contents of the configuration will vary by Connector depending on the specific data provider.
8+
9+
### Connector
10+
11+
The npm package that implements an integration with a specific data provider. To learn about the specification of a connector, see our [Spec doc](LINK).
12+
13+
### Stream
14+
15+
A Stream is a data source that can be subscribed to. What message type or types represent a Stream for a given Integration will depend on the specific Integration. For example, in GitHub or BitBucket, a repository is a Stream. In Bugsnag, a "project" is a Stream. PagerDuty does not have any concept of "projects", so the PagerDuty Connector emits a single Stream for the account the configured API token has access to.
16+
17+
### Envolope
18+
19+
A wrapper that has a set of Records and metadata.
20+
21+
### Record
22+
23+
A record is an object that must conform to the the schema defined here: https://github.com/codeclimate/codeclimate-connector-sdk/tree/master/schemas
24+
25+
### State
26+
27+
Connectors can use their `StateManager` object to store state indicating their progress in a sync operation, and to store additional metadata. In the event a sync operation is interrupted partway through, it will be retried at a later time, and the the Connector can then retrieve the stored state to avoid re-doing work it already completed.
28+
29+
## Operations
30+
31+
### Verify
32+
33+
The Verify operation allows a Connector to validate that the configuration
34+
it's been given meets its requirements. For example, that all required keys
35+
are present and of the required type and format, as well as validating
36+
that things like API credentials are valid and usable.
37+
38+
If you're building a Connector, this is a required method.
39+
40+
### Discover
41+
42+
The Discover operation allows a Connector identify streams of data that can be synced from an Integration.
43+
A stream is a a data source from an integration that a user may choose to subscribe to: e.g. in GitHub or a CI tool, the streams might be repositories from that tool, or from a project management tool the Streams might be projects.
44+
45+
If you're building a Connector, this is a required method.
46+
47+
### Sync
48+
49+
The Sync operation allows a Connector ingests new data from a Stream of an Integration and
50+
produces an Envolope with a set of Records and metadata information from the sync.
51+
52+
If you're building a Connector, this is a required method.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Connector Developer’s Guide
2+
3+
## Build a connector (step-by-step guide)
4+
5+
In this tutorial, we’ll explain how to create a connector that will
6+
allow you to extract data from a source and produce records in an
7+
structure data form.
8+
9+
To get you up and running quickly, we have built a [scaffolding
10+
template tool](https://github.com/codeclimate/create-codeclimate-connector)
11+
that will create a new project with some scaffolding and stubbed
12+
unit tests, and is setup to use TypeScript.
13+
14+
For the purposes of this exercise, we're going to build a Connector
15+
with PagerDuty.
16+
17+
1. Create a new Connector by running `yarn create codeclimate-connector <connector-slug>`.
18+
For this example, we will run ``yarn create codeclimate-connector pagerduty`. The project
19+
will be created in a directory called `./codeclimate-connector-pagerduty`.
20+
21+
2. Take a look at the created `README.md` and `src/Client.ts` in your project to get
22+
familiar with a Connector implementation.
23+
24+
3. Write a valid configuration to `connector-config.json`. This will depend of the
25+
data source you're integrating with. In this case, PagerDuty requires a valid
26+
[API token](https://v2.developer.pagerduty.com/docs/authentication) to be able to make
27+
requests to their API. Implement the `verifyConfiguration()` method to validate
28+
the token:
29+
30+
```
31+
if (!this.apiTokenPresent()) {
32+
return Promise.resolve({
33+
isValid: false,
34+
errorMessages: ["apiToken must be present"],
35+
})
36+
}
37+
38+
return this.buildApiClient().get("me").
39+
then(() => {
40+
return { isValid: true }
41+
}).
42+
catch((err) => {
43+
let msg = "An error occurred"
44+
45+
if (err instanceof ResponseError) {
46+
msg = err.message
47+
}
48+
49+
return {
50+
isValid: false,
51+
errorMessages: [msg],
52+
}
53+
})
54+
```
55+
56+
4. A connector is able to consume from a stream or streams. In the case of
57+
PagerDuty, there's no concept of "projects" the connector can subscribe too,
58+
so we will emit a single Stream for the account the configured API token by
59+
implement the `discoverStream()` method:
60+
61+
```
62+
return new Promise((resolve, _reject) => {
63+
this.recordProducer.produce({
64+
record: {
65+
_type: "Stream",
66+
id: "unavailable",
67+
self: "https://pagerduty.com",
68+
name: "PagerDuty Account",
69+
}
70+
})
71+
72+
resolve()
73+
})
74+
```
75+
76+
5. Sync data from PagerDuty from an earliest data cutoff data for the
77+
stream returned by `discoverStream()`. The recommended pattern for
78+
Connectors is to start by fetching recent data, and walk backwards in time. When
79+
implementing that pattern, the `Client` should stop when it encounters data
80+
from before `earliestDataCutoff`. When publishing records, an exception will be
81+
raised with details when an invalid record is produced.
82+
83+
6. To ensure the project's current code has been compiled into `./lib` for
84+
execution, run `yarn build`.
85+
7. Then, to run a sync, run the following (replace `YYYY-MM-DD` with the date
86+
you want to sync back to):
87+
88+
```
89+
yarn run \
90+
codeclimate-connector sync-stream \
91+
pagerduty \
92+
connector-config.json \
93+
'$(shell cat stream.json)' \
94+
YYYY-MM-DD
95+
```
96+
97+
Go to [PagerDuty Connector repository](https://github.com/codeclimate/codeclimate-connector-pagerduty) to dive in the implementation.
98+
99+
## Publishing your connector
100+
101+
Use `yarn publish` to release a new version of the package. This will prompt you to
102+
enter a new version number, release it on npm, and then push the new version to GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Data Consumer’s Guide
2+
3+
## Understanding data types
4+
5+
6+
The Code Climate Data Engineering Platform has a standard Data Schema,
7+
representing 50+ common software development units, like epics, pull requests,
8+
builds, incidents and more. Get a overview of the different data types
9+
on the [Schema reference](docs/schemas/README.md).
10+
11+
12+
## Invoking a connector on the CLI
13+
14+
For example, you're interested on using the CLI with the PagerDuty
15+
connector. You can run the following commands to verify, discover
16+
and sync:
17+
18+
```
19+
# Verify
20+
yarn run \
21+
codeclimate-connector verify-configuration \
22+
pagerduty \
23+
connector-config.json
24+
25+
# Discover
26+
yarn run \
27+
codeclimate-connector discover-streams \
28+
pagerduty \
29+
connector-config.json
30+
31+
# Sync
32+
yarn run \
33+
codeclimate-connector sync-stream \
34+
circleci \
35+
connector-config.json \
36+
'$(shell cat stream.json)' \ # stream.json is the output from the previous command
37+
2020-01-01
38+
```

docs/connectors/getting_started.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Getting Started
2+
3+
## Using a Connector
4+
Follow the [Data Consumer’s Guide](docs/connectors/data_consumer_guide.md)
5+
to learn how to use a Code Climate Connector. An easy-to-follow introduction
6+
to understanding data types, running a connector through the CLI and following
7+
the state of a connector.
8+
9+
## Concepts
10+
Learn the [Concepts](docs/connectors/concepts.md) of Code Climate Connectors by
11+
reviewing its components and operations.
12+
13+
## Building a Connector
14+
15+
Learn how to integrate with a data source by following
16+
a [Connector Developer’s Guide](docs/connectors/connector_developer_guide.md).
17+
This tutorial will cover a step-by-step guide on implementing the connector
18+
and how to publish it.
19+
20+
## Reference
21+
22+
For a detailed overview of the Data Schema Connectors Specification,
23+
check out the [Reference](docs/connecotrs/reference.md).
24+
25+
## Reference implementations
26+
27+
- PagerDuty: https://github.com/codeclimate/codeclimate-connector-pagerduty
28+
- CodeCov https://github.com/codeclimate/codeclimate-connector-codecov
29+
- CircleCI https://github.com/codeclimate/codeclimate-connector-circleci
30+
31+
## Community and Support
32+
33+
Code Climate Connectors is an open source project. We welcome contributions
34+
from the community. Here you will find helpful information for interacting
35+
with the core team and contributing to the project:
36+
37+
* [Join the conversation on Slack](https://slack.codeclimate.com/) with
38+
hundreds of community contributors
39+
* Subscribe to our Developer Program mailing list (https://codeclimate.com/dev_form/)
40+
to stay up-to-date

docs/connectors/reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Reference
2+
3+
## [Data Schema](spec/schemas/readme.md)
4+
## [Connector Specification](spec/connectors/SPEC.md)

0 commit comments

Comments
 (0)