Commit 3dade855 authored by Meet Mangukiya's avatar Meet Mangukiya

GitLab: Incorporate the usage of *Token classes

parent 0f06985c
......@@ -4,7 +4,7 @@ Contains the Hoster implementation for GitLab.
import logging
from IGitt.GitLab import get
from IGitt.GitLab import get, GitLabOAuthToken, GitLabPrivateToken
from IGitt.Interfaces import AccessLevel
from IGitt.Interfaces.Hoster import Hoster
from IGitt.GitLab.GitLabRepository import GitLabRepository
......@@ -18,13 +18,13 @@ class GitLab(Hoster):
A high level interface to GitLab.
"""
def __init__(self, oauth_token):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken)):
"""
Creates a new GitLab Hoster object.
:param oauth_token: An OAuth token to use for authentication.
:param token: A Token object to be used for authentication.
"""
self._token = oauth_token
self._token = token
@property
def master_repositories(self):
......@@ -50,7 +50,7 @@ class GitLab(Hoster):
Retrieves repositories owned by the authenticated user.
>>> from os import environ
>>> GitLab = GitLab(environ['GITLAB_TEST_TOKEN'])
>>> GitLab = GitLab(GitLabOAuthToken(viron['GITLAB_TEST_TOKEN']))
>>> sorted(map(lambda x: x.full_name, GitLab.owned_repositories)
{'gitmate-test-user/test'}
......@@ -66,7 +66,7 @@ class GitLab(Hoster):
Retrieves the full names of repositories this user can write to.
>>> from os import environ
>>> GitLab = GitLab(environ['GITLAB_TEST_TOKEN'])
>>> GitLab = GitLab(GitLabOAuthToken(viron['GITLAB_TEST_TOKEN']))
>>> sorted(map(lambda x: x.full_name, GitLab.write_repositories))
['gitmate-test-user/test', 'nkprince007/gitmate-test']
......@@ -90,7 +90,7 @@ class GitLab(Hoster):
Retrieve a given repository.
>>> from os import environ
>>> source = GitLab(environ['GITLAB_TEST_TOKEN'])
>>> GitLab = GitLab(GitLabOAuthToken(viron['GITLAB_TEST_TOKEN']))
>>> repo = source.get_repo('gitmate-test-user/test')
>>> isinstance(repo, GitLabRepository)
True
......
......@@ -5,6 +5,7 @@ from urllib.parse import quote_plus
from datetime import datetime
from IGitt.GitLab import delete, put, GitLabMixin
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
from IGitt.Interfaces.Comment import Comment
from IGitt.Interfaces.Comment import CommentType
......@@ -15,12 +16,13 @@ class GitLabComment(Comment, GitLabMixin):
and an author, which can ofcourse be deleted.
"""
def __init__(self, oauth_token: str, repository: str, iid: int,
comment_type: CommentType, comment_id: int):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken),
repository: str, iid: int, comment_type: CommentType,
comment_id: int):
"""
Creates a new GitLabComment with the given data.
:param oauth_token: An OAuth token to be used.
:param token: A Token object to be used for authentication.
:param repository: The full namespace of the repository.
:param iid: The unique identifier that links the holder of comment to
GitLab. i.e. which identifies the MR or issue or snippet
......@@ -29,7 +31,7 @@ class GitLabComment(Comment, GitLabMixin):
GitLabComment types.
:param comment_id: The id of comment.
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._type = comment_type
self._url = '/projects/{repo}/{c_type}/{iid}/notes/{c_id}'.format(
......@@ -49,7 +51,7 @@ class GitLabComment(Comment, GitLabMixin):
Retrieves the username of the comment author.
>>> from os import environ
>>> note = GitLabComment(environ['GITLAB_TEST_TOKEN'],
>>> note = GitLabComment(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1,
... CommentType.ISSUE, 31500135)
>>> note.author
......@@ -65,7 +67,7 @@ class GitLabComment(Comment, GitLabMixin):
Retrieves the content of the comment.
>>> from os import environ
>>> note = GitLabComment(environ['GITLAB_TEST_TOKEN'],
>>> note = GitLabComment(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1,
... CommentType.ISSUE, 31500135)
>>> note.body
......@@ -91,7 +93,7 @@ class GitLabComment(Comment, GitLabMixin):
Retrieves a timestamp on when the comment was created.
>>> from os import environ
>>> note = GitLabComment(environ['GITLAB_TEST_TOKEN'],
>>> note = GitLabComment(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1,
... CommentType.ISSUE, 31500135)
>>> note.created
......@@ -106,7 +108,7 @@ class GitLabComment(Comment, GitLabMixin):
Retrieves a timestamp on when the comment was updated the last time.
>>> from os import environ
>>> note = GitLabComment(environ['GITLAB_TEST_TOKEN'],
>>> note = GitLabComment(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1,
... CommentType.ISSUE, 31500135)
>>> note.updated
......
......@@ -6,6 +6,7 @@ from urllib.parse import quote_plus
from IGitt import ElementDoesntExistError
from IGitt.GitHub.GitHubCommit import get_diff_index
from IGitt.GitLab import get, post, GitLabMixin
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
from IGitt.GitLab.GitLabRepository import GitLabRepository
from IGitt.Interfaces.Commit import Commit
from IGitt.Interfaces.CommitStatus import Status, CommitStatus
......@@ -25,19 +26,19 @@ class GitLabCommit(Commit, GitLabMixin):
Represents a commit on GitLab.
"""
def __init__(self, oauth_token: str, repository: str, sha: (str, None),
branch: (str, None)=None):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken),
repository: str, sha: (str, None), branch: (str, None)=None):
"""
Creates a new GitLabCommit object.
:param oauth_token: A valid OAuth token for authentication.
:param token: A Token object to be used for authentication.
:param repository: The full repository name.
:param sha: The full commit SHA, if None given provide a branch.
:param branch: A branch name if SHA is unavailable. Note that lazy
loading won't work in that case.
"""
assert sha or branch, "Either full SHA or branch name has to be given!"
self._token = oauth_token
self._token = token
self._repository = repository
self._sha = sha
self._branch = branch
......@@ -50,8 +51,10 @@ class GitLabCommit(Commit, GitLabMixin):
Retrieves the SHA of the commit:
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '674498')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '674498'
... )
>>> commit.sha
'674498'
......@@ -65,8 +68,10 @@ class GitLabCommit(Commit, GitLabMixin):
Retrieves the repository that holds this commit.
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '3fc4b86')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86'
... )
>>> commit.repository.full_name
'gitmate-test-user/test'
......@@ -81,8 +86,10 @@ class GitLabCommit(Commit, GitLabMixin):
will be returned.
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '3fc4b86')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86'
... )
>>> commit.parent.sha
'674498fd415cfadc35c5eb28b8951e800f357c6f'
......@@ -121,8 +128,10 @@ class GitLabCommit(Commit, GitLabMixin):
Adds the given status to the commit.
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '3fc4b860')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86'
... )
>>> status = CommitStatus(Status.FAILED, 'Theres a problem',
... 'gitmate/test')
>>> commit.set_status(status)
......@@ -155,8 +164,10 @@ class GitLabCommit(Commit, GitLabMixin):
Retrieves the unified diff for the commit.
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '3fc4b86')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86'
... )
>>> assert (commit.get_patch_for_file('README.md') ==
... '--- a/README.md\n+++ b/README.md\n@@ -1,2 +1,4 @@\n '
... '# test\n a test repo\n+\n+a tst pr\n')
......@@ -186,8 +197,10 @@ class GitLabCommit(Commit, GitLabMixin):
Places a comment on the commit.
>>> from os import environ
>>> commit = GitLabCommit(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', '3fc4b86')
>>> commit = GitLabCommit(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86'
... )
So this line places a comment on the bottom of the commit,
not associated to any particular piece of code:
......
......@@ -8,6 +8,7 @@ from IGitt.GitLab import delete, GitLabMixin
from IGitt.GitLab import get
from IGitt.GitLab import put
from IGitt.GitLab import post
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
from IGitt.GitLab.GitLabComment import GitLabComment
from IGitt.Interfaces.Comment import CommentType
from IGitt.Interfaces.Issue import Issue
......@@ -18,25 +19,26 @@ class GitLabIssue(Issue, GitLabMixin):
This class represents an issue on GitLab.
"""
def __init__(self, oauth_token: str, repository: str, issue_iid: int):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken),
repository: str, issue_iid: int):
"""
Creates a new GitLabIssue with the given credentials.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/repo_that_doesnt_exist', 1)
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
RuntimeError: ({'message': 'Not Found', ...}, 404)
:param oauth_token: The OAuth token.
:param token: A Token object to be used for authentication.
:param repository: The full name of the repository.
e.g. ``sils/baritone``.
:param issue_iid: The issue internal identification number.
:raises RuntimeError: If something goes wrong (network, auth, ...)
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._iid = issue_iid
self._url = '/projects/{repo}/issues/{issue_iid}'.format(
......@@ -48,8 +50,9 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves the title of the issue.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.title
'Take it serious, son!'
......@@ -88,7 +91,7 @@ class GitLabIssue(Issue, GitLabMixin):
Returns the issue "number" or id.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.number
1
......@@ -103,12 +106,12 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves the assignee of the issue:
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.assignee
'gitmate-test-user'
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2)
>>> issue.assignee # Returns None, unassigned
......@@ -162,7 +165,7 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves the main description of the issue.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.description
'I am a serious issue. Fix me soon, dude.'
......@@ -176,7 +179,7 @@ class GitLabIssue(Issue, GitLabMixin):
Adds a comment to the issue.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> comment = issue.add_comment("Doh!")
......@@ -206,7 +209,7 @@ class GitLabIssue(Issue, GitLabMixin):
CE here - https://gitlab.com/gitlab-org/gitlab-ce/issues/32057
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 3)
>>> comments = issue.comments
>>> for comment in comments:
......@@ -226,7 +229,7 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves all labels associated with this bug.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.labels
set()
......@@ -261,7 +264,7 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves a set of captions that are available for labelling bugs.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> sorted(issue.available_labels)
['a', 'b', 'c']
......@@ -278,7 +281,7 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves a timestamp on when the issue was created.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 4)
>>> issue.created
datetime.datetime(2017, 6, 5, 9, 45, 20, 678000)
......@@ -292,7 +295,7 @@ class GitLabIssue(Issue, GitLabMixin):
Retrieves a timestamp on when the issue was updated the last time.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 4)
>>> issue.updated
datetime.datetime(2017, 6, 5, 9, 45, 56, 115000)
......@@ -330,7 +333,7 @@ class GitLabIssue(Issue, GitLabMixin):
Get's the state of the issue.
>>> from os import environ
>>> issue = GitLabIssue(environ['GITLAB_TEST_TOKEN'],
>>> issue = GitLabIssue(GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.state
'reopened'
......@@ -352,15 +355,18 @@ class GitLabIssue(Issue, GitLabMixin):
return self.data['state']
@staticmethod
def create(token: str, repository: str, title: str, body: str=''):
def create(token: (GitLabOAuthToken, GitLabPrivateToken), repository: str,
title: str, body: str=''):
"""
Create a new issue with given title and body.
>>> from os import environ
>>> issue = GitLabIssue.create(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test',
... 'test issue title',
... 'sample description')
>>> issue = GitLabIssue.create(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test',
... 'test issue title',
... 'sample description'
... )
>>> issue.state
'opened'
......
......@@ -6,7 +6,7 @@ import re
from functools import lru_cache
from urllib.parse import quote_plus
from IGitt.GitLab import get
from IGitt.GitLab import get, GitLabOAuthToken, GitLabPrivateToken
from IGitt.GitLab.GitLabCommit import GitLabCommit
from IGitt.GitLab.GitLabIssue import GitLabIssue
from IGitt.Interfaces.MergeRequest import MergeRequest
......@@ -18,15 +18,16 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
A Merge Request on GitLab.
"""
def __init__(self, oauth_token: str, repository: str, mr_iid: int):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken),
repository: str, mr_iid: int):
"""
Creates a new GitLabMergeRequest object.
:param oauth_token: The OAuth token to authenticate with.
:param token: A Token object to be used for authentication.
:param repository: The repository containing the MR.
:param mr_iid: The unique identifier for GitLab MRs.
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._iid = mr_iid
self._url = '/projects/{repo}/merge_requests/{iid}'.format(
......@@ -58,8 +59,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Retrieves the base commit as a GitLabCommit object.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 2)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> pr.base.sha
'198dd16f8249ea98ed41876efe27d068b69fa215'
......@@ -84,8 +87,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Retrieves the head commit as a GitLabCommit object.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 2)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> pr.head.sha
'99f484ae167dcfcc35008ba3b5b564443d425ee0'
......@@ -101,8 +106,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Retrieves a tuple of commit objects that are included in the PR.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 2)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> assert ([commit.sha for commit in pr.commits] == [
... '99f484ae167dcfcc35008ba3b5b564443d425ee0',
... 'bbd11b50412d34072f1889e4cea04a32de183605'])
......@@ -119,8 +126,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Retrieves the repository where this comes from.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 2)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> pr.repository.full_name
'gitmate-test-user/test'
......@@ -135,8 +144,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Retrieves affected files from a GitLab merge request.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 7)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> pr.affected_files
{'README.md'}
......@@ -151,8 +162,10 @@ class GitLabMergeRequest(GitLabIssue, MergeRequest):
Gets additions and deletions of a merge request.
>>> from os import environ
>>> pr = GitLabMergeRequest(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test', 7)
>>> pr = GitLabMergeRequest(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2
... )
>>> pr.diffstat
(2, 0)
......
......@@ -5,6 +5,7 @@ from urllib.parse import quote_plus
from IGitt import ElementAlreadyExistsError, ElementDoesntExistError
from IGitt.GitLab import delete, get, post, GitLabMixin
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
from IGitt.GitLab.GitLabIssue import GitLabIssue
from IGitt.Interfaces.Repository import Repository
from IGitt.Interfaces.Repository import WebhookEvents
......@@ -27,15 +28,16 @@ class GitLabRepository(Repository, GitLabMixin):
Represents a repository on GitLab.
"""
def __init__(self, oauth_token: str, repository: str):
def __init__(self, token: (GitLabOAuthToken, GitLabPrivateToken),
repository: str):
"""
Creates a new GitLabRepository object with the given credentials.
:param oauth_token: The OAuth token.
:param token: A Token object to be used for authentication.
:param repository: The full name of the repository,
e.g. ``sils/baritone``.
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._url = '/projects/' + quote_plus(repository)
......@@ -54,8 +56,10 @@ class GitLabRepository(Repository, GitLabMixin):
Retrieves the full name of the repository, e.g. "sils/baritone".
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> repo.full_name
'gitmate-test-user/test'
......@@ -69,23 +73,28 @@ class GitLabRepository(Repository, GitLabMixin):
Retrieves the URL of the repository.
>>> from os import environ as env
>>> repo = GitLabRepository(env['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> expected = 'https://{}@gitlab.com/gitmate-test-user/test.git'
>>> assert repo.clone_url == expected.format(env['GITLAB_TEST_TOKEN'])
:return: A URL that can be used to clone the repository with Git.
"""
return self.data['http_url_to_repo'].replace(
'gitlab.com', 'oauth2:' + self._token + '@gitlab.com', 1)
'gitlab.com',
'oauth2:' + self._token.value + '@gitlab.com', 1)
def get_labels(self) -> {str}:
"""
Retrieves the labels of the repository.
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> sorted(repo.get_labels())
['a', 'b', 'c']
......@@ -103,8 +112,10 @@ class GitLabRepository(Repository, GitLabMixin):
an exception:
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> sorted(repo.get_labels())
['a', 'b', 'c']
>>> repo.create_label('c', '#555555')
......@@ -133,8 +144,10 @@ class GitLabRepository(Repository, GitLabMixin):
Take a given repository:
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> sorted(repo.get_labels())
['a', 'b', 'c']
......@@ -170,8 +183,10 @@ class GitLabRepository(Repository, GitLabMixin):
Retrieves an issue:
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> repo.get_issue(1).title
'Take it serious, son!'
......@@ -287,8 +302,10 @@ class GitLabRepository(Repository, GitLabMixin):
Retrieves a set of merge request objects.
>>> from os import environ
>>> repo = GitLabRepository(environ['GITLAB_TEST_TOKEN'],
... 'gitmate-test-user/test')
>>> repo = GitLabRepository(
... GitLabOAuthToken(environ['GITLAB_TEST_TOKEN']),
... 'gitmate-test-user/test'
... )
>>> len(repo.merge_requests)
4
"""
......
interactions:
- request:
body: '{"description": "test body", "title": "test title"}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['51']
Content-Type: [application/json]
User-Agent: [python-requests/2.18.1]
method: POST
uri: https://gitlab.com/api/v4/projects/gitmate-test-user%2Ftest/issues?User-Agent=IGitt
response:
body: {string: '{"id":5795065,"iid":31,"project_id":3439658,"title":"test title","description":"test
body","state":"opened","created_at":"2017-06-21T06:16:05.391Z","updated_at":"2017-06-21T06:16:05.391Z","labels":[],"milestone":null,"assignees":[],"author":{"name":"Meet
Mangukiya","username":"meetmangukiya","id":707601,"state":"active","avatar_url":"https://gitlab.com/uploads/system/user/avatar/707601/avatar.png","web_url":"https://gitlab.com/meetmangukiya"},"assignee":null,"user_notes_count":0,"upvotes":0,"downvotes":0,"due_date":null,"confidential":false,"weight":null,"web_url":"https://gitlab.com/gitmate-test-user/test/issues/31","subscribed":true}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['643']
Content-Type: [application/json]
Date: ['Wed, 21 Jun 2017 06:16:05 GMT']
Etag: [W/"f6f6f35eaf078afff2e845b5652ed2a1"]
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [84437d2f-6ef2-42fd-850b-731bc7e8b9c4]
X-Runtime: ['0.687935']
status: {code: 201, message: Created}
version: 1
......@@ -5,6 +5,7 @@ import datetime
import vcr
import requests_mock
from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab.GitLabComment import GitLabComment
from IGitt.Interfaces.Comment import CommentType
......@@ -16,10 +17,11 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitLabCommentTest(unittest.TestCase):
def setUp(self):
self.comment = GitLabComment(os.environ.get('GITLAB_TEST_TOKEN', ''),
token = GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', ''))
self.comment = GitLabComment(token,
'gitmate-test-user/test', 1,
CommentType.ISSUE, 31500135)
self.issue_comment = GitLabComment(os.environ.get('GITLAB_TEST_TOKEN', ''),
self.issue_comment = GitLabComment(token,
'gitmate-test-user/test', 30,
CommentType.ISSUE, 32616806)
......
......@@ -3,6 +3,7 @@ import unittest
import vcr
from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab.GitLabCommit import GitLabCommit
from IGitt.Interfaces.CommitStatus import CommitStatus, Status
......@@ -15,7 +16,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitLabCommitTest(unittest.TestCase):
def setUp(self):
self.commit = GitLabCommit(os.environ.get('GITLAB_TEST_TOKEN', ''),
self.token = GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', ''))
self.commit = GitLabCommit(self.token,
'gitmate-test-user/test',
'3fc4b860e0a2c17819934d678decacd914271e5c')
......@@ -34,7 +36,7 @@ class GitLabCommitTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitLab/cassettes/gitlab_commit_status.yaml')
def test_set_status(self):
self.commit = GitLabCommit(os.environ.get('GITLAB_TEST_TOKEN', ''),
self.commit = GitLabCommit(self.token,
'gitmate-test-user/test',
'3fc4b860e0a2c17819934d678decacd914271e5c')
status = CommitStatus(Status.FAILED, 'Theres a problem',
......@@ -56,7 +58,7 @@ class GitLabCommitTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitLab/cassettes/gitlab_commit_comment.yaml')
def test_comment(self):
self.commit = GitLabCommit(os.environ.get('GITLAB_TEST_TOKEN', ''),
self.commit = GitLabCommit(self.token,
'gitmate-test-user/test',
'3fc4b860e0a2c17819934d678decacd914271e5c')
self.commit.comment('An issue is here')
......
......@@ -3,6 +3,7 @@ import unittest
import vcr
from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab.GitLab import GitLab
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
......@@ -13,7 +14,7 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class TestGitLab(unittest.TestCase):
def setUp(self):
self.gl = GitLab(os.environ.get('GITLAB_TEST_TOKEN', ''))
self.gl = GitLab(GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', '')))
@my_vcr.use_cassette('tests/GitLab/cassettes/test_gitlab_hoster_master.yaml')
def test_master_repositories(self):
......
from IGitt.GitLab import GitLabOAuthToken, GitLabPrivateToken
def test_tokens():
oauth_token = GitLabOAuthToken('test')
assert oauth_token.parameter == {'access_token': 'test'}
assert oauth_token.value == 'test'
private_token = GitLabPrivateToken('test')
assert private_token.parameter == {'private_token': 'test'}
assert private_token.value == 'test'
......@@ -4,6 +4,7 @@ import datetime
import vcr
from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab.GitLabIssue import GitLabIssue
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
......@@ -14,7 +15,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitLabIssueTest(unittest.TestCase):