Skip to content

Commit 4342e84

Browse files
committed
Add 'init' function for setting up new projects
1 parent 552fbab commit 4342e84

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ merge (or close) pull requests.
88
The file `.gitconsensus.yaml` needs to be placed in the repository to be managed. Any rule set to `false` or ommitted
99
will be skipped.
1010

11+
You can run `gitconsensus init` to start with a template configuration in the current working directory.
12+
1113
```yaml
1214
# Which version of the consensus rules to use
1315
version: 3
@@ -95,6 +97,15 @@ gitconsensus auth
9597
You will be asked for your username, password, and 2fa token (if configured). This will be used to get an authentication
9698
token from Github that will be used in place of your username and password (which are never saved).
9799

100+
### Initialization
101+
102+
Initialize the configuration for a specific project. If no template is provided the `recommended` settings will be used.
103+
All settings come from the [gitconsensus_examples](https://github.com/gitconsensus/gitconsensus_examples) project.
104+
105+
```shell
106+
gitconsensus init [TEMPLATE]
107+
```
108+
98109
### Merge
99110

100111
Merge all pull requests that meet consensus rules.

gitconsensus/gitconsensus.py

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import github3
33
import os
44
import random
5+
import requests
56
from gitconsensus import config
67
from gitconsensus.repository import Repository
78
import string
@@ -31,6 +32,28 @@ def twofacallback(*args):
3132
fd.write(auth.token + '\n')
3233

3334

35+
@cli.command(short_help="Create a new gitconsensus configuration")
36+
@click.argument('template', required=False)
37+
def init(template):
38+
if not template:
39+
template = 'recommended'
40+
41+
if os.path.isfile('.gitconsensus.yaml'):
42+
click.echo('.gitconsensus.yaml already exists.')
43+
exit(-1)
44+
45+
baseurl = 'https://raw.githubusercontent.com/gitconsensus/gitconsensus_examples/master/examples/%s/.gitconsensus.yaml'
46+
url = baseurl % (template)
47+
response = requests.get(url)
48+
49+
if not response.ok:
50+
click.echo('Unable to find template "%s"' % (template))
51+
exit(-1)
52+
53+
with open('.gitconsensus.yaml', 'wb') as f:
54+
f.write(response.content)
55+
56+
3457
@cli.command(short_help="List open pull requests and their status")
3558
@click.argument('username')
3659
@click.argument('repository_name')

0 commit comments

Comments
 (0)