Commit ed582a4b authored by Meet Mangukiya's avatar Meet Mangukiya

IGitt: Add get_mr to Repository Interface and implementations

Closes #56
parent dc167aba
......@@ -168,6 +168,18 @@ class GitHubRepository(Repository, GitHubMixin):
"""
return GitHubIssue(self._token, self.full_name, issue_number)
def get_mr(self, mr_number: int):
"""
Retrieves an MR:
:param mr_number: The merge_request ID of the MR to retrieve.
:return: A MergeRequest object.
:raises ElementDoesntExistError: If the MR doesn't exist.
:raises RuntimeError: If something goes wrong (network, auth...).
"""
from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
return GitHubMergeRequest(self._token, self.full_name, mr_number)
@property
def hooks(self):
"""
......
......@@ -169,6 +169,18 @@ class GitLabRepository(Repository, GitLabMixin):
"""
return GitLabIssue(self._token, self.full_name, issue_number)
def get_mr(self, mr_number: int):
"""
Retrieves an MR.
:param mr_number: The MR IID of the merge_request on GitLab.
:return: A MergeRequest object.
:raises ElementDoesntExistError: If the MR doesn't exist.
:raises RuntimeError: If something goes wrong (network, auth...).
"""
from IGitt.GitLab.GitLabMergeRequest import GitLabMergeRequest
return GitLabMergeRequest(self._token, self.full_name, mr_number)
@property
def hooks(self) -> {str}:
"""
......
......@@ -55,6 +55,15 @@ class Repository:
"""
raise NotImplementedError
def get_mr(self, mr_number: int):
"""
Retrieves an MR.
:param mr_number: The merge_request ID of the MR to retrieve.
:return: An MR object.
"""
raise NotImplementedError
def create_label(self, name: str, color: str):
"""
Creates a new label.
......
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.18.1]
method: GET
uri: https://api.github.com/repos/gitmate-test-user/test/issues/11?User-Agent=IGitt
response:
body:
string: !!binary |
H4sIAAAAAAAAA62V247aMBRFf6XyM4wTKJBGqvoT7UurCpnEBKuOndoOIxrNv3fbyQwMGS4BnkjM
OcvnutOQ2kiSko1zlU0pZZV4KoTb1KunTJfU8EpbioOSOT523Lpxbbmh/okKa2tuaRyTEQmGwmmz
W94MBEayFZf2dsQ+JtqiGqpYyV+ARjolV+4x8FcYuHz7MGqLAnPjSnlUhIOmnGhHVUvZNkPkJI2T
xZfPySyZjIiqyxU3OIpHxAknOfrtG1iZT5lE11RBdcUVfnG1by9JGyJ1IRQMrZAWxx45W8Tz2SQa
EbZljpnjLoVDO+3Gx3MyrRyKEyappp37t+3XKYCF6SieTPzF5+bQ0yztYjlfnc5oraXUz/A6DvP9
gO/B9M0DwbTPqMhAb3g0VLsNR3UQsp+7QthLQ3cQRLBusHHWLUXu/S2qanh+dSCdPcJ4VoigCTsc
QPXKZkZUTmh1fVXeeYGiTcGU+MeGUeDlpyioxNWZBGt4XbNhByVszRtaGbFl2c6nbnjGxRZFHIg6
8gPJ7Sq/Pj/8lqCkwvEly0u/KWsmLX95lTCS/vodeue8uV8vmEud/eEY92CKNbJWFIrDQGF19++2
dS6FxJJq9fb/m+ik2MHMcLDzJXPgT6J4Po7jcZR8j6M0itLp5Cfuq6v8nc1iHM2DTZLOonSy8DZe
ATpMG4WXkaXhfyHtQDfn9/Ls98GTus/D+ZW9KGi5WK9v1cMn74xEK+ayzc2Q4E3Q3pXOd61gdZVb
4XUvl71UcHOQ4/k8iaPpBfGMTornq/8d6vlRaAP7gmQG6WrvyttF9hTqHsXtM++S3z7ucVr8AftQ
ztGYwcLcRw5V6T5huGT3GY/R7z53uJi//AdNnjfUHgsAAA==
headers:
Access-Control-Allow-Origin: ['*']
Access-Control-Expose-Headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
X-Poll-Interval']
Cache-Control: ['private, max-age=60, s-maxage=60']
Content-Encoding: [gzip]
Content-Security-Policy: [default-src 'none']
Content-Type: [application/json; charset=utf-8]
Date: ['Thu, 15 Jun 2017 12:15:49 GMT']
ETag: [W/"350f9d06c706fe14cebd4dbf64fa6c3e"]
Last-Modified: ['Thu, 08 Jun 2017 18:50:27 GMT']
Server: [GitHub.com]
Status: [200 OK]
Strict-Transport-Security: [max-age=31536000; includeSubdomains; preload]
Vary: ['Accept, Authorization, Cookie, X-GitHub-OTP']
X-Accepted-OAuth-Scopes: ['public_repo, repo']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [deny]
X-GitHub-Media-Type: [github.v3; format=json]
X-GitHub-Request-Id: ['9AA0:2F227:2CC5FA:39D50E:59427A75']
X-OAuth-Scopes: ['admin:gpg_key, admin:org, admin:org_hook, admin:public_key,
admin:repo_hook, delete_repo, gist, notifications, repo, user']
X-RateLimit-Limit: ['5000']
X-RateLimit-Remaining: ['4996']
X-RateLimit-Reset: ['1497529303']
X-Runtime-rack: ['0.053997']
X-XSS-Protection: [1; mode=block]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.18.1]
method: GET
uri: https://api.github.com/repos/gitmate-test-user/test/pulls/11?User-Agent=IGitt
response:
body:
string: !!binary |
H4sIAAAAAAAAA+1b25KjNhD9lS1e4xnABttDVWrzEZuXpFIuAcJWBgMReKZmqfn3nBYCX/Dgi/yQ
SvGwswbUR61bt/q0VFs7mVqBtamqogxsmxXieS2qzS58jvKtLXmRlzZebFnFnypeVk+7kkubftnF
Lk1L23WtiSViK3iZLrz5wvcmANumq2PcA8wBtAYsFklyr/gzCUOhglXR5m4QJU3NKssdP0G5pYeU
vO6ibLcNubQC151YZYXuRK/nBc9QTZpHrxw9mLC05BOrElVKX6mTC/ktSvNSZGubCuN/lKchsIIa
cmuRoWAp0lIPgr9w5/7UmVjsjVVMnuquXpYzPcSEE+VZxbNKjfbO1uLf336dAXAtNQoNr0UVD80V
QittrcvwFNCFkjxN83dInap5PAn3wHYnAWWa3+iRG6UhUdt5teHoHaj8SQ0VZXW9Eqp0jVVRVisR
kzzGU0oeX62ILg813jNoUKt1poB2YRlJUVQiz65X6EgKKLlcs0z8ZLehQIpmkVry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Z+fn2uibQhbcYcm+jYAQGIy
2oBUNejYuoXA1gZJIMVVJ6RkjLgtzVlsomeHAbxmBA00bQAOJ5dKUBkgKvlDwI5NNUHdgxxCZ3kl
EhFdw9kPGtgjnPo7MkcRnzAw0phrlYgE5i/CPRpARQ6aNKQBQCMQ8xOg5CnHVDaBbCFqu0msxLxI
8w9TUvkAhaxuj/J33Cd39sNZBP48cP1zlD/4/l6ZYlduLmQOYEj19MMvZFfxt82s9mMrCmiI5ISK
ZdnmLvH8214qGJRCDiI7XepX1/h26tcuSkLPTb7lBbYYbVaiFD/xu0lwtnuFKN9lSK6A3n2nrCp5
5f2rdn/RAmxYuWrWsRVUcodkKL0pZP43j5ALOHi3Nx0HL9/FqzgSpO1PFxiq4KytHEpuhZS5TpE2
WRVKser623KLZRNeAgYiBwWsgD61bVINjHnCdmm1anbaiFK3DDkZaX1SygkrY5iS14VpHREL3z02
xPvc81/mbuQsPZctvciN4ynzl/7MZ2zhsNjzQ45UkjfHqIzE+/nDDF+RGiOfdl/uuW+MjBPRfciR
eD9NXo/EuzJwNx8zgsSYoTtzxusrszhm6AYOxn3Vaf+lDN1IvN98pHEk3kfinULZkXg/4ygGeQfs
3EbivUljjMS7CQU0Eu8qKdBR+iPxPhLvI/HeHmM2sSwj8f71XZ6ReB+J9/8n8b5KRYagBidVS56C
WK+tTUOwG115A6NP59jOwF3Mm6h7c3TTDRiqy8+A3HfJDIDtbuFRmPvLDAA/ueZhWEd7fXCgiofU
0D8ToPsJu6yHVOC67WkJGtL2KI8h9O3XPijL1Nw66jJe6pGFdJuwyaZJTnmowzddkRXVSGe3I2Rx
6VaivsEU4qZUkx3bzy3kunpzAe+2TGQV/uFmXcSy1TbHZUxI63OfJK66fIpzCXEs1O00nTdL+f4p
2uDgEhKrCfl8fP/8F30iEZSkOgAA
headers:
Access-Control-Allow-Origin: ['*']
Access-Control-Expose-Headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
X-Poll-Interval']
Cache-Control: ['private, max-age=60, s-maxage=60']
Content-Encoding: [gzip]
Content-Security-Policy: [default-src 'none']
Content-Type: [application/json; charset=utf-8]
Date: ['Thu, 15 Jun 2017 12:15:50 GMT']
ETag: [W/"6179b163abf148037f2b126fc28872c7"]
Last-Modified: ['Thu, 08 Jun 2017 18:50:27 GMT']
Server: [GitHub.com]
Status: [200 OK]
Strict-Transport-Security: [max-age=31536000; includeSubdomains; preload]
Vary: ['Accept, Authorization, Cookie, X-GitHub-OTP', Accept-Encoding]
X-Accepted-OAuth-Scopes: ['']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [deny]
X-GitHub-Media-Type: [github.v3; format=json]
X-GitHub-Request-Id: ['AC52:2F228:620D50:7EE5DE:59427A76']
X-OAuth-Scopes: ['admin:gpg_key, admin:org, admin:org_hook, admin:public_key,
admin:repo_hook, delete_repo, gist, notifications, repo, user']
X-RateLimit-Limit: ['5000']
X-RateLimit-Remaining: ['4995']
X-RateLimit-Reset: ['1497529303']
X-Runtime-rack: ['0.101486']
X-Served-By: [ef96c2e493b28ffea49b891b085ed2dd]
X-XSS-Protection: [1; mode=block]
status: {code: 200, message: OK}
version: 1
......@@ -52,6 +52,10 @@ class TestGitHubRepository(unittest.TestCase):
def test_get_issue(self):
self.assertEqual(self.repo.get_issue(1).title, 'test issue')
@my_vcr.use_cassette('tests/GitHub/cassettes/github_repo_get_mr.yaml')
def test_get_mr(self):
self.assertEqual(self.repo.get_mr(11).title, 'testpr closing/opening')
@my_vcr.use_cassette('tests/GitHub/cassettes/github_repo_merge_requests.yaml')
def test_merge_requests(self):
self.assertEqual(len(self.repo.merge_requests), 3)
......
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.18.1]
method: GET
uri: https://gitlab.com/api/v4/projects/gitmate-test-user%2Ftest/merge_requests/2?User-Agent=IGitt
response:
body: {string: '{"id":3757647,"iid":2,"project_id":3439658,"title":"Sils/severalcommits","description":"","state":"reopened","created_at":"2017-06-07T03:51:41.112Z","updated_at":"2017-06-09T09:45:46.971Z","target_branch":"master","source_branch":"sils/severalcommits","upvotes":0,"downvotes":0,"author":{"name":"GitMate","username":"gitmate-test-user","id":1369631,"state":"active","avatar_url":"https://secure.gravatar.com/avatar/27e08ed25afa8578cb3a346964f0de32?s=80&d=identicon","web_url":"https://gitlab.com/gitmate-test-user"},"assignee":null,"source_project_id":3439658,"target_project_id":3439658,"labels":[],"work_in_progress":false,"milestone":null,"merge_when_pipeline_succeeds":false,"merge_status":"unchecked","sha":"99f484ae167dcfcc35008ba3b5b564443d425ee0","merge_commit_sha":null,"user_notes_count":0,"approvals_before_merge":null,"should_remove_source_branch":null,"force_remove_source_branch":null,"squash":false,"web_url":"https://gitlab.com/gitmate-test-user/test/merge_requests/2","subscribed":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['1004']
Content-Type: [application/json]
Date: ['Thu, 15 Jun 2017 12:36:55 GMT']
Etag: [W/"f042120a3b0b31abb2567a29f99bf71e"]
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [e022bdc1-6f33-481c-975d-bcc640be08ab]
X-Runtime: ['0.886523']
status: {code: 200, message: OK}
version: 1
......@@ -51,6 +51,10 @@ class TestGitLabRepository(unittest.TestCase):
def test_get_issue(self):
self.assertEqual(self.repo.get_issue(1).title, 'new title')
@my_vcr.use_cassette('tests/GitLab/cassettes/gitlab_repo_get_mr.yaml')
def test_get_mr(self):
self.assertEqual(self.repo.get_mr(2).title, 'Sils/severalcommits')
@my_vcr.use_cassette('tests/GitLab/cassettes/gitlab_repo_create_issue.yaml')
def test_create_issue(self):
self.assertEqual(self.repo.create_issue(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment