Skip to content

Commit 7e23713

Browse files
author
Nate Ricklin
committed
add github-merge
1 parent 57c8061 commit 7e23713

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

Diff for: githubtools/merge.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Usage:
3+
github-merge-pull-request -h <head> -b <base> -t <token> -r <repo>
4+
5+
Options:
6+
-h <head>, --head <head> Head: the branch you're pulling from.
7+
-b <base>, --base <base> Base: the branch you're pulling to.
8+
-t <token>, --token <token> github access token
9+
-r <repository>, --repo <repository> github repository
10+
"""
11+
from docopt import docopt
12+
from github import Github
13+
14+
def main(argv=None, test=False):
15+
arguments = docopt(__doc__, argv=argv)
16+
head = arguments['--head']
17+
base = arguments['--base']
18+
token = arguments['--token']
19+
repo = arguments['--repo']
20+
21+
g = Github(token)
22+
r = g.get_repo(repo)
23+
print "Merging %s into %s in repo %s." % (head, base, repo)
24+
c = r.merge(head=head, base=base)
25+
26+
if test:
27+
return c
28+
29+
if __name__ == "__main__":
30+
main()

Diff for: setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
'github-commit-status = githubtools.commit_status:main',
7474
'github-create-pull-request = githubtools.commit_status:main',
7575
'github-merge-pull-request = githubtools.merge_pull_request:main',
76+
'github-merge = githubtools.merge:main'
7677
]
7778
}
7879
)

Diff for: tests/all_tests.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import githubtools.commit_status
44
import githubtools.create_pull_request
55
import githubtools.merge_pull_request
6+
import githubtools.merge
67
import vcr
78
from docopt import DocoptExit
89

@@ -33,6 +34,14 @@ def test_merge_pull_request_no_args(self):
3334
else:
3435
self.assertTrue(False)
3536

37+
def test_merge_no_args(self):
38+
try:
39+
githubtools.merge.main()
40+
except DocoptExit as e:
41+
self.assertTrue(str(e).startswith("Usage:"))
42+
else:
43+
self.assertTrue(False)
44+
3645
@vcr.use_cassette()
3746
def test_create_commit_status(self):
3847
args = "-t faketoken -r nricklin/githubtools --url https://yahoo.com --context context56 -c d3c3dfe -d description -s success"
@@ -93,10 +102,13 @@ def test_merge_pull_request_by_branch_names_with_no_pull_request_existing(self):
93102
self.assertEquals(str(e),"No pull request found matching head: dummy_branch and base: master.")
94103
else:
95104
self.assertTrue(False)
96-
97-
98-
99105

106+
@vcr.use_cassette(filter_headers=['authorization'])
107+
def test_merge(self):
108+
args = "-t faketoken -r nricklin/githubtools -h ac36ee8c403a90cba8e2981fe5b93f273785e604 -b test1"
109+
c = githubtools.merge.main(args, test=True)
110+
self.assertEquals(c.parents[1].sha,'ac36ee8c403a90cba8e2981fe5b93f273785e604')
111+
100112
def get_suite():
101113
return unittest.TestLoader().loadTestsFromTestCase(GithubtoolsTests)
102114

Diff for: tests/test_merge

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
interactions:
2+
- request:
3+
body: '{"head": "ac36ee8c403a90cba8e2981fe5b93f273785e604", "base": "test1"}'
4+
headers:
5+
Accept: ['*/*']
6+
Accept-Encoding: ['gzip, deflate']
7+
Connection: [keep-alive]
8+
Content-Length: ['69']
9+
Content-Type: [application/json]
10+
User-Agent: [PyGithub/Python]
11+
method: POST
12+
uri: https://api.github.com/repos/nricklin/githubtools/merges
13+
response:
14+
body: {string: !!python/unicode '{"sha":"ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82","commit":{"author":{"name":"nricklin","email":"[email protected]","date":"2016-02-13T16:19:29Z"},"committer":{"name":"nricklin","email":"[email protected]","date":"2016-02-13T16:19:29Z"},"message":"Merge
15+
ac36ee8c403a90cba8e2981fe5b93f273785e604 into test1","tree":{"sha":"5eb9b77124da5f3e8c0661be18edff633f15d84a","url":"https://api.github.com/repos/nricklin/githubtools/git/trees/5eb9b77124da5f3e8c0661be18edff633f15d84a"},"url":"https://api.github.com/repos/nricklin/githubtools/git/commits/ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82","comment_count":0},"url":"https://api.github.com/repos/nricklin/githubtools/commits/ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82","html_url":"https://github.com/nricklin/githubtools/commit/ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82","comments_url":"https://api.github.com/repos/nricklin/githubtools/commits/ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82/comments","author":{"login":"nricklin","id":5749532,"avatar_url":"https://avatars.githubusercontent.com/u/5749532?v=3","gravatar_id":"","url":"https://api.github.com/users/nricklin","html_url":"https://github.com/nricklin","followers_url":"https://api.github.com/users/nricklin/followers","following_url":"https://api.github.com/users/nricklin/following{/other_user}","gists_url":"https://api.github.com/users/nricklin/gists{/gist_id}","starred_url":"https://api.github.com/users/nricklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nricklin/subscriptions","organizations_url":"https://api.github.com/users/nricklin/orgs","repos_url":"https://api.github.com/users/nricklin/repos","events_url":"https://api.github.com/users/nricklin/events{/privacy}","received_events_url":"https://api.github.com/users/nricklin/received_events","type":"User","site_admin":false},"committer":{"login":"nricklin","id":5749532,"avatar_url":"https://avatars.githubusercontent.com/u/5749532?v=3","gravatar_id":"","url":"https://api.github.com/users/nricklin","html_url":"https://github.com/nricklin","followers_url":"https://api.github.com/users/nricklin/followers","following_url":"https://api.github.com/users/nricklin/following{/other_user}","gists_url":"https://api.github.com/users/nricklin/gists{/gist_id}","starred_url":"https://api.github.com/users/nricklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nricklin/subscriptions","organizations_url":"https://api.github.com/users/nricklin/orgs","repos_url":"https://api.github.com/users/nricklin/repos","events_url":"https://api.github.com/users/nricklin/events{/privacy}","received_events_url":"https://api.github.com/users/nricklin/received_events","type":"User","site_admin":false},"parents":[{"sha":"1e58bb940d8fb2feaffa8403784b8b9ffad280ae","url":"https://api.github.com/repos/nricklin/githubtools/commits/1e58bb940d8fb2feaffa8403784b8b9ffad280ae","html_url":"https://github.com/nricklin/githubtools/commit/1e58bb940d8fb2feaffa8403784b8b9ffad280ae"},{"sha":"ac36ee8c403a90cba8e2981fe5b93f273785e604","url":"https://api.github.com/repos/nricklin/githubtools/commits/ac36ee8c403a90cba8e2981fe5b93f273785e604","html_url":"https://github.com/nricklin/githubtools/commit/ac36ee8c403a90cba8e2981fe5b93f273785e604"}]}'}
16+
headers:
17+
access-control-allow-credentials: ['true']
18+
access-control-allow-origin: ['*']
19+
access-control-expose-headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
20+
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
21+
X-Poll-Interval']
22+
cache-control: ['private, max-age=60, s-maxage=60']
23+
content-length: ['3226']
24+
content-security-policy: [default-src 'none']
25+
content-type: [application/json; charset=utf-8]
26+
date: ['Sat, 13 Feb 2016 16:19:29 GMT']
27+
etag: ['"56261dd829baae9c2aa7a00fd734c3c8"']
28+
location: ['https://api.github.com/repos/nricklin/githubtools/commits/ba5d05685b33ac73a7cc7a4c4d1f736eeece0b82']
29+
server: [GitHub.com]
30+
status: [201 Created]
31+
strict-transport-security: [max-age=31536000; includeSubdomains; preload]
32+
vary: ['Accept, Authorization, Cookie, X-GitHub-OTP', Accept-Encoding]
33+
x-accepted-oauth-scopes: ['']
34+
x-content-type-options: [nosniff]
35+
x-frame-options: [deny]
36+
x-github-media-type: [github.v3]
37+
x-github-request-id: ['18094E54:C8D3:115025AE:56BF5791']
38+
x-oauth-scopes: [repo]
39+
x-ratelimit-limit: ['5000']
40+
x-ratelimit-remaining: ['4987']
41+
x-ratelimit-reset: ['1455383166']
42+
x-served-by: [cee4c0729c8e9147e7abcb45b9d69689]
43+
x-xss-protection: [1; mode=block]
44+
status: {code: 201, message: Created}
45+
version: 1

0 commit comments

Comments
 (0)