Commit 7a8cf14e authored by Sebastian Latacz's avatar Sebastian Latacz

Implement functionality to add Milestones to Merge Requests

parent 4a044453
Pipeline #23471135 passed with stage
in 45 seconds
......@@ -24,7 +24,7 @@ from IGitt.GitHub.GitHubCommit import GitHubCommit
from IGitt.GitHub.GitHubIssue import GitHubIssue
from IGitt.GitHub.GitHubUser import GitHubUser
from IGitt.Interfaces.MergeRequest import MergeRequest
from IGitt.Interfaces import get, put, MergeRequestStates
from IGitt.Interfaces import get, put, MergeRequestStates, patch
# Issue is used as a Mixin, super() is never called by design!
......@@ -333,3 +333,24 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
put(self._token, self._mr_url + '/merge', merge_options)
self.refresh()
@property
def milestone(self):
"""
Retrieves the milestone.
"""
from IGitt.GitHub.GitHubMilestone import GitHubMilestone
return GitHubMilestone.from_data(
self.data['milestone'], self._token, self._repository,
self.data['milestone']['number']
) if self.data['milestone'] else None
@milestone.setter
def milestone(self, new_milestone):
"""
Setter for the Milestone.
Delete the Milestone with passing a 'None'
"""
self.data = patch(
self._token, self.url,
{'milestone': new_milestone.number if new_milestone else ''})
......@@ -331,3 +331,24 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
_gitlab_merge_when_pipeline_succeeds
self.data = put(self._token, self.url + '/merge', merge_options)
@property
def milestone(self):
"""
Retrieves the milestone.
"""
from IGitt.GitLab.GitLabProjectMilestone import GitLabProjectMilestone
return GitLabProjectMilestone.from_data(
self.data['milestone'], self._token, self._repository,
self.data['milestone']['id']
) if self.data['milestone'] else None
@milestone.setter
def milestone(self, new_milestone):
"""
Setter for the Milestone.
Delete the Milestone with passing a 'None'
"""
self.data = put(
self._token, self.url,
{'milestone_id': new_milestone.number if new_milestone else ''})
......@@ -11,6 +11,7 @@ from IGitt.Interfaces.Commit import Commit
from IGitt.Interfaces.CommitStatus import Status
from IGitt.Interfaces.Issue import Issue
from IGitt.Interfaces.User import User
from IGitt.Interfaces.Milestone import Milestone
class MergeRequest(Issue):
......@@ -217,3 +218,17 @@ class MergeRequest(Issue):
:raises NotImplementedError: If an unused parameter is passed.
"""
raise NotImplementedError
@property
def milestone(self) -> Milestone:
"""
Retrieves the milestone.
"""
raise NotImplementedError
@milestone.setter
def milestone(self, new_milestone) -> Milestone:
"""
Setter for the Milestone.
"""
raise NotImplementedError
......@@ -4,6 +4,7 @@ import datetime
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
from IGitt.Interfaces.MergeRequest import MergeRequestStates
from IGitt.GitHub.GitHubMilestone import GitHubMilestone
from tests import IGittTestCase
......@@ -152,3 +153,14 @@ class GitHubMergeRequestTest(IGittTestCase):
mr = GitHubMergeRequest(self.token, 'gitmate-test-user/test', 134)
mr.merge(message=commit_msg, sha=head_sha, _github_merge_method=method)
self.assertEqual(mr.state, MergeRequestStates.MERGED)
def test_milestone_setter(self):
merge_request = GitHubMergeRequest(self.token,
'gitmate-test-user/test', 147)
self.assertEqual(merge_request.milestone, None)
merge_request.milestone = GitHubMilestone(self.token,
'gitmate-test-user/test', 1)
self.assertEqual(merge_request.milestone.title,
'Permanent IGitt test milestone. DO NOT DELETE.')
merge_request.milestone = None
self.assertEqual(merge_request.milestone, None)
......@@ -12,7 +12,7 @@ interactions:
uri: https://gitlab.com/api/v4/projects/gitmate-test-user%2Ftest/merge_requests/77
response:
body: {string: '{"id":9967635,"iid":77,"project_id":3439658,"title":"Nonsense
MR to test Milestones on MR implementation. DO NOT DELETE.","description":"","state":"opened","created_at":"2018-05-18T10:23:02.196Z","updated_at":"2018-05-18T14:40:05.630Z","target_branch":"gitmate-test-user-patch-1","source_branch":"hello","upvotes":0,"downvotes":0,"author":{"id":463976,"name":"Sebastian
MR to test Milestones on MR implementation. DO NOT DELETE.","description":"","state":"opened","created_at":"2018-05-18T10:23:02.196Z","updated_at":"2018-05-18T15:55:22.740Z","target_branch":"gitmate-test-user-patch-1","source_branch":"hello","upvotes":0,"downvotes":0,"author":{"id":463976,"name":"Sebastian
Latacz","username":"seblat","state":"active","avatar_url":"https://assets.gitlab-static.net/uploads/-/system/user/avatar/463976/avatar.png","web_url":"https://gitlab.com/seblat"},"assignee":null,"source_project_id":3439658,"target_project_id":3439658,"labels":[],"work_in_progress":false,"milestone":{"id":513937,"iid":1,"project_id":3439658,"title":"Permanent
IGitt test milestone. DO NOT DELETE.","description":"Description update to
test updated getter","state":"active","created_at":"2018-04-25T09:11:00.029Z","updated_at":"2018-04-30T11:22:02.350Z","due_date":null,"start_date":null},"merge_when_pipeline_succeeds":false,"merge_status":"cannot_be_merged","sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","merge_commit_sha":null,"user_notes_count":0,"discussion_locked":null,"should_remove_source_branch":null,"force_remove_source_branch":false,"web_url":"https://gitlab.com/gitmate-test-user/test/merge_requests/77","time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"subscribed":true,"changes_count":"1","merged_by":null,"merged_at":null,"closed_by":null,"closed_at":null,"latest_build_started_at":null,"latest_build_finished_at":null,"first_deployed_to_production_at":null,"pipeline":null,"diff_refs":{"base_sha":"674498fd415cfadc35c5eb28b8951e800f357c6f","head_sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","start_sha":"8c31d04e826dc38e6b3e74143f83f9890b89c71c"},"approvals_before_merge":null,"squash":false}'}
......@@ -20,20 +20,20 @@ interactions:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['1848']
Content-Type: [application/json]
Date: ['Fri, 18 May 2018 14:40:06 GMT']
Etag: [W/"344f4bfdb422ae9482454a4152a03166"]
Date: ['Fri, 18 May 2018 15:55:26 GMT']
Etag: [W/"ce9cced6761a12962046ce3eaee0f515"]
RateLimit-Limit: ['600']
RateLimit-Observed: ['2']
RateLimit-Remaining: ['598']
RateLimit-Reset: ['1526654466']
RateLimit-ResetTime: ['Sat, 18 May 2018 14:41:06 GMT']
RateLimit-Observed: ['1']
RateLimit-Remaining: ['599']
RateLimit-Reset: ['1526658986']
RateLimit-ResetTime: ['Sat, 18 May 2018 15:56:26 GMT']
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [c9e7cd2a-e253-48c5-8bdb-7fdbc0bf0218]
X-Runtime: ['1.395232']
X-Request-Id: [397cab9b-fd01-4ff2-b238-88f4c58ba30f]
X-Runtime: ['6.289292']
status: {code: 200, message: OK}
- request:
body: '{"milestone_id": ""}'
......@@ -43,31 +43,65 @@ interactions:
Connection: [keep-alive]
Content-Length: ['20']
Content-Type: [application/json]
If-None-Match: [W/"344f4bfdb422ae9482454a4152a03166"]
If-None-Match: [W/"ce9cced6761a12962046ce3eaee0f515"]
User-Agent: [IGitt]
method: PUT
uri: https://gitlab.com/api/v4/projects/gitmate-test-user%2Ftest/merge_requests/77
response:
body: {string: '{"id":9967635,"iid":77,"project_id":3439658,"title":"Nonsense
MR to test Milestones on MR implementation. DO NOT DELETE.","description":"","state":"opened","created_at":"2018-05-18T10:23:02.196Z","updated_at":"2018-05-18T14:40:10.712Z","target_branch":"gitmate-test-user-patch-1","source_branch":"hello","upvotes":0,"downvotes":0,"author":{"id":463976,"name":"Sebastian
MR to test Milestones on MR implementation. DO NOT DELETE.","description":"","state":"opened","created_at":"2018-05-18T10:23:02.196Z","updated_at":"2018-05-18T15:55:28.671Z","target_branch":"gitmate-test-user-patch-1","source_branch":"hello","upvotes":0,"downvotes":0,"author":{"id":463976,"name":"Sebastian
Latacz","username":"seblat","state":"active","avatar_url":"https://assets.gitlab-static.net/uploads/-/system/user/avatar/463976/avatar.png","web_url":"https://gitlab.com/seblat"},"assignee":null,"source_project_id":3439658,"target_project_id":3439658,"labels":[],"work_in_progress":false,"milestone":null,"merge_when_pipeline_succeeds":false,"merge_status":"cannot_be_merged","sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","merge_commit_sha":null,"user_notes_count":0,"discussion_locked":null,"should_remove_source_branch":null,"force_remove_source_branch":false,"web_url":"https://gitlab.com/gitmate-test-user/test/merge_requests/77","time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"subscribed":true,"changes_count":"1","merged_by":null,"merged_at":null,"closed_by":null,"closed_at":null,"latest_build_started_at":null,"latest_build_finished_at":null,"first_deployed_to_production_at":null,"pipeline":null,"diff_refs":{"base_sha":"674498fd415cfadc35c5eb28b8951e800f357c6f","head_sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","start_sha":"8c31d04e826dc38e6b3e74143f83f9890b89c71c"},"approvals_before_merge":null,"squash":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['1564']
Content-Type: [application/json]
Date: ['Fri, 18 May 2018 15:55:30 GMT']
Etag: [W/"066d179c3a6b7b1525876fa7d8193d4d"]
RateLimit-Limit: ['600']
RateLimit-Observed: ['1']
RateLimit-Remaining: ['599']
RateLimit-Reset: ['1526658990']
RateLimit-ResetTime: ['Sat, 18 May 2018 15:56:30 GMT']
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [25d1d29a-1a19-4597-b910-2f69dffbdbca]
X-Runtime: ['2.288590']
status: {code: 200, message: OK}
- request:
body: '{}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['2']
Content-Type: [application/json]
User-Agent: [IGitt]
method: GET
uri: https://gitlab.com/api/v4/projects/gitmate-test-user%2Ftest/merge_requests/77?per_page=100
response:
body: {string: '{"id":9967635,"iid":77,"project_id":3439658,"title":"Nonsense
MR to test Milestones on MR implementation. DO NOT DELETE.","description":"","state":"opened","created_at":"2018-05-18T10:23:02.196Z","updated_at":"2018-05-18T15:55:28.671Z","target_branch":"gitmate-test-user-patch-1","source_branch":"hello","upvotes":0,"downvotes":0,"author":{"id":463976,"name":"Sebastian
Latacz","username":"seblat","state":"active","avatar_url":"https://assets.gitlab-static.net/uploads/-/system/user/avatar/463976/avatar.png","web_url":"https://gitlab.com/seblat"},"assignee":null,"source_project_id":3439658,"target_project_id":3439658,"labels":[],"work_in_progress":false,"milestone":null,"merge_when_pipeline_succeeds":false,"merge_status":"cannot_be_merged","sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","merge_commit_sha":null,"user_notes_count":0,"discussion_locked":null,"should_remove_source_branch":null,"force_remove_source_branch":false,"web_url":"https://gitlab.com/gitmate-test-user/test/merge_requests/77","time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"subscribed":true,"changes_count":"1","merged_by":null,"merged_at":null,"closed_by":null,"closed_at":null,"latest_build_started_at":null,"latest_build_finished_at":null,"first_deployed_to_production_at":null,"pipeline":null,"diff_refs":{"base_sha":"674498fd415cfadc35c5eb28b8951e800f357c6f","head_sha":"a37bb904b39a4aabee24f52ff98a0a988a41a24a","start_sha":"8c31d04e826dc38e6b3e74143f83f9890b89c71c"},"approvals_before_merge":null,"squash":false}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['1564']
Content-Type: [application/json]
Date: ['Fri, 18 May 2018 14:40:12 GMT']
Etag: [W/"a698304ab5ceae5746e33bc92bc1eaae"]
Date: ['Tue, 05 Jun 2018 11:44:52 GMT']
Etag: [W/"066d179c3a6b7b1525876fa7d8193d4d"]
RateLimit-Limit: ['600']
RateLimit-Observed: ['1']
RateLimit-Remaining: ['599']
RateLimit-Reset: ['1526654472']
RateLimit-ResetTime: ['Sat, 18 May 2018 14:41:12 GMT']
RateLimit-Reset: ['1528199152']
RateLimit-ResetTime: ['Wed, 05 Jun 2018 11:45:52 GMT']
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [2717ec57-f3cc-4365-a5d2-5b74a4a6d5d8]
X-Runtime: ['2.131985']
X-Request-Id: [edee37d0-9e60-45bd-b2bd-c587d76ae1cf]
X-Runtime: ['0.324244']
status: {code: 200, message: OK}
version: 1
......@@ -5,6 +5,7 @@ from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab.GitLabMergeRequest import GitLabMergeRequest
from IGitt.GitLab.GitLabUser import GitLabUser
from IGitt.Interfaces import MergeRequestStates
from IGitt.GitLab.GitLabProjectMilestone import GitLabProjectMilestone
from tests import IGittTestCase
......@@ -150,3 +151,14 @@ class GitLabMergeRequestTest(IGittTestCase):
should_remove_source_branch=True,
_gitlab_merge_when_pipeline_succeeds=True)
self.assertEqual(mr.state, MergeRequestStates.MERGED)
def test_milestone_setter(self):
merge_request = GitLabMergeRequest(self.token,
'gitmate-test-user/test', 77)
self.assertEqual(merge_request.milestone, None)
merge_request.milestone = GitLabProjectMilestone(
self.token, 'gitmate-test-user/test', 513937)
self.assertEqual(merge_request.milestone.title,
'Permanent IGitt test milestone. DO NOT DELETE.')
merge_request.milestone = None
self.assertEqual(merge_request.milestone, None)
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