Skip to content

Commit

Permalink
Merge pull request #51 from intuit/init2
Browse files Browse the repository at this point in the history
Add createLabels tool
  • Loading branch information
hipstersmoothie authored Dec 14, 2018
2 parents 296f124 + f6ccf37 commit 79bec78
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 112 deletions.
Binary file modified docs/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

:hammer: Tool APIs :wrench:

- [Setup](pages/auto-init.md)
- [auto init](pages/auto-init.md#auto-init)
- [auto init-labels](pages/auto-init.md#auto-init-labels)
- [Publishing](pages/publishing.md)
- [auto version](pages/auto-version.md)
- [auto changelog](pages/auto-changelog.md)
Expand Down
37 changes: 37 additions & 0 deletions docs/pages/auto-init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Initialization

`auto-release` provides some tools to quickly set up your project. If you do not want to use the interactive experience all these options can be configured via the [.autorc](./autorc.md) and most can be configure via CLI options.

## `auto init`

Interactive setup for most configurable options.

```sh
$ auto init --help

usage: auto.js init [-h]

Optional arguments:
-h, --help Show this help message and exit.
```

## `auto init-labels`

Create your projects labels on github.

```sh
$ auto init-labels --help

usage: auto.js init-labels [-h] [-v] [-vv] [--githubApi GITHUBAPI]

Optional arguments:
-h, --help Show this help message and exit.
-v, --verbose Show some more logs
-vv, --very-verbose Show a lot more logs
--githubApi GITHUBAPI
Github API to use
```

::: message is-warning
:warning: For this to work you must have a `GH_TOKEN` set, ex: `GH_TOKEN=YOUR_TOKEN auto init-labels`
:::
60 changes: 32 additions & 28 deletions docs/pages/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,54 @@ Before we do anything we must first install `auto-release-cli` as a dev dependen
yarn add -D auto-release-cli
```

## Enterprise

If you are using enterprise github `auto-release` lets you configure the github API URL that it uses. You can configure this by using the CLI option `--githubApi`, by setting the value in your [.autorc](./autorc.md#githubApi), or during `auto init`.

## Configuration

To quickly configure most options run `auto init`.
Getting started with `auto-release` is super easy.

If you do this you still must configure the environment variables and add the labels to your project. `auto init` cannot automate these steps.
1. `auto init` (optional)
2. `auto init-labels`
3. Configure environment variables
4. Set up script

### Environment Variables
### 1. Initialize Options

You must configure some environment variables for publishing and releasing.
Initialize all options and configure label text. If this is not run then `auto-release` will use the default configuration.

- `GH_TOKEN` - Used for updating the changelog and publishing the GitHub release
- `NPM_TOKEN` - Used to publish to npm.
### 2. Labels

If you are publishing from the CI you must inject the `NPM_TOKEN` into your `.npmrc`.
After that, you need to set up the labels on your github project. The types of labels that `auto-release` uses are:

- Versioning Labels - used to calculate version numbers and make releases. To change them refer to [this](./autorc.md#versioning-labels).
- Changelog Labels - These labels do not effect the version calculation but they will change the section the PR displays in the changelog. These are customizable too, and you can even add your own sections. Read more [here](./autorc.md#changelog-titles)

To create the labels for your project on Github, run the following command with your `GH_TOKEN`.

```sh
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
GH_TOKEN=YOUR_TOKEN auto init-labels
```

### Labels
### 3. Environment Variables

After that, set up the labels on your github project. The following labels are the defaults. To change them refer to [this](./autorc.md#versioning-labels).
You must configure some environment variables for publishing and releasing to work properly.

#### Versioning Labels:
- `GH_TOKEN` - Used for updating the changelog and publishing the GitHub release
- `NPM_TOKEN` - Used to publish to npm.

- `major` - create a major release
- `minor` - create a minor release
- `patch` - create a patch release
- `no-release` - do not create a release
- `release` (optional) - only used with `onlyPublishWithReleaseLabel`
- `prerelease` (optional) - create pre release
If you are publishing from the CI you must inject the `NPM_TOKEN` into your `.npmrc`.

#### Changelog Labels
```sh
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
```

These labels do not effect the version calculation but they will change the section the PR displays in the changelog. These are customizable too, and you can even add your own sections. Read more [here](./autorc.md#changelog-titles)
### 4. Script

- `internal` - the changes do not effect the code and is more about tooling
- `documentation` - the changes effect the documentation
`auto-release` is written so that each tool it exposes is useful in isolation. It also provides workflows for those who don't care about the details of each tool and just want their code release.

## Quick Setup
#### Quick Setup

To version, changelog, publish and release your code all at the same time, we've included the `shipit` tool. This tool takes the default `auto` workflow and puts it into one command.

Expand All @@ -57,7 +65,7 @@ To version, changelog, publish and release your code all at the same time, we've
}
```

## Detailed Setup
#### Detailed Setup

The simplest workflow to get set up in just the `package.json` is by adding the following to your `package.json`. With this setup your application will not be able to use the `no-release` flag, but everything else will work just fine

Expand All @@ -71,7 +79,7 @@ The simplest workflow to get set up in just the `package.json` is by adding the
}
```

### Enabling `no-release` label
##### Enabling `no-release` label

To use the `no-release` label you have to get a little more involved and use a shell script. We could do the `if` checks in the `package.json`, but this would get messy and hard to read very quickly.

Expand Down Expand Up @@ -118,7 +126,3 @@ if [ ! -z "$VERSION" ]; then
auto release
fi
```

## Enterprise

If you are using enterprise github `auto-release` lets you configure the github API URL that it uses. You can configure this by using the CLI option `--githubApi` or by setting the value in your [.autorc](./autorc.md#githubApi).
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"docs:publish": "ignite --publish"
},
"dependencies": {
"@octokit/rest": "^16.1.0",
"@octokit/rest": "^16.2.0",
"@types/argparse": "1.0.35",
"@types/cosmiconfig": "5.0.3",
"@types/node-fetch": "2.1.4",
Expand All @@ -57,20 +57,20 @@
},
"devDependencies": {
"@types/jest": "~23.3.10",
"@types/node": "~10.12.11",
"@types/node": "~10.12.15",
"@types/url-join": "^0.8.2",
"all-contributors-cli": "^5.4.1",
"husky": "^1.2.0",
"ignite": "^1.6.5",
"husky": "^1.2.1",
"ignite": "^1.6.6",
"jest": "~23.6.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.3",
"ts-jest": "~23.10.5",
"tslint": "~5.11.0",
"tslint-config-prettier": "~1.17.0",
"tslint-xo": "~0.10.0",
"typescript": "~3.2.1",
"typescript-tslint-plugin": "^0.1.2"
"typescript": "~3.2.2",
"typescript-tslint-plugin": "^0.2.0"
},
"prettier": {
"singleQuote": true
Expand Down
13 changes: 7 additions & 6 deletions src/__tests__/github-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,15 @@ describe('GithubRelease', () => {
});

test('should be able to configure labels', async () => {
const labels = new Map();
labels.set(SEMVER.major, 'Version: Major');
labels.set(SEMVER.minor, 'Version: Minor');
labels.set(SEMVER.patch, 'Version: Patch');
labels.set('release', 'Deploy');

const gh = new GithubRelease(undefined, {
logger,
labels: {
major: 'Version: Major',
minor: 'Version: Minor',
patch: 'Version: Patch',
release: 'Deploy'
}
labels
});
const commits = [
makeCommitFromMsg('First (#1234)'),
Expand Down
10 changes: 1 addition & 9 deletions src/__tests__/semver.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defaultLabels } from '../github-release';
import SEMVER, { calculateSemVerBump, getHigherSemverTag } from '../semver';

test('ranks releases right', () => {
Expand All @@ -6,15 +7,6 @@ test('ranks releases right', () => {
expect(getHigherSemverTag('minor', 'patch')).toBe('minor');
});

const defaultLabels = {
major: 'major',
minor: 'minor',
patch: 'patch',
'no-release': 'no-release',
release: 'release',
prerelease: 'prerelease'
};

describe('calculateSemVerBump', () => {
test('publishes pre-releases', () => {
expect(calculateSemVerBump([['minor', 'prerelease']], defaultLabels)).toBe(
Expand Down
1 change: 1 addition & 0 deletions src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const PARSERS: [string, ParserFunction][] = [
['version', addVersionParser],
['comment', addCommentParser],
['changelog', addChangelogParser],
['init-labels', addLoggingParser],
['init', () => undefined],
['shipit', () => undefined]
];
Expand Down
56 changes: 54 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import GHub from '@octokit/rest';
import { ICommit, parseGit } from 'parse-git';
import { Memoize } from 'typescript-memoize';

import { ILogger } from './github-release';
import {
defaultLabelsDescriptions,
ILogger,
VersionLabel
} from './github-release';
import execPromise from './utils/exec-promise';

export interface IGithubOptions {
Expand Down Expand Up @@ -50,7 +54,10 @@ export default class Github {
`Initializing Github with: ${this.options.baseUrl}`
);
this.ghub = new GHub({
baseUrl: this.options.baseUrl
baseUrl: this.options.baseUrl,
headers: {
accept: 'application/vnd.github.symmetra-preview+json'
}
});
}

Expand Down Expand Up @@ -145,6 +152,32 @@ export default class Github {
}
}

public async getProjectLabels() {
this.logger.verbose.info(
`Getting labels for project: ${this.options.repo}`
);

await this.authenticate();

const args = {
owner: this.options.owner,
repo: this.options.repo
};

try {
const labels = await this.ghub.issues.listLabelsForRepo(args);
this.logger.veryVerbose.info(
'Got response for "listLabelsForRepo":\n',
labels
);
this.logger.verbose.info('Found labels on project:\n', labels.data);

return labels.data.map(l => l.name);
} catch (e) {
throw new GithubAPIError('listLabelsOnIssue', args, e);
}
}

public async getGitLog(start: string, end = 'HEAD'): Promise<ICommit[]> {
const gitlog = await execPromise(
`git log --name-status ${start.trim()}..${end.trim()}`
Expand Down Expand Up @@ -214,6 +247,25 @@ export default class Github {
return result;
}

public async createLabel(label: VersionLabel, name: string) {
await this.authenticate();

this.logger.verbose.info(`Creating "${label}" label :\n${name}`);

const result = await this.ghub.issues.createLabel({
name,
owner: this.options.owner,
repo: this.options.repo,
color: Math.floor(Math.random() * 16777215).toString(16),
description: defaultLabelsDescriptions.get(label)
});

this.logger.veryVerbose.info('Got response from createLabel\n', result);
this.logger.verbose.info('Created label on Github.');

return result;
}

public async getProject() {
this.logger.verbose.info('Getting project from Github');

Expand Down
Loading

0 comments on commit 79bec78

Please sign in to comment.