Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for Gitlab #188

Closed
swmcc opened this issue Jun 21, 2021 · 5 comments
Closed

[Feature] Add support for Gitlab #188

swmcc opened this issue Jun 21, 2021 · 5 comments
Labels
enhancement New feature or request python Pull requests that update Python code

Comments

@swmcc
Copy link

swmcc commented Jun 21, 2021

I would like a feature to flip between or include gitlab reps.

Describe the solution you'd like
Either a flag that switches between github and gitlab repos or a way to include both in the same screen.
A clear and concise description of what you want to happen.

Am wiling to help out if you want. Do you think this might be an interesting feature? Could possibly extend to Bitbucket?

@apoclyps
Copy link
Owner

cheers @swmcc - I'm onboard for adding both. I'm happy to take a run at adding Gitlab support and as a follow it; it might be nice for you to tackle Bitbucket if you are interested?

@apoclyps
Copy link
Owner

https://pypi.org/project/python-gitlab/ looks like a suitable candidate for interacting with the Gitlab API via python:

python-gitlab has a similar API to pygithub: https://python-gitlab.readthedocs.io/en/stable/api-usage.html

@apoclyps
Copy link
Owner

apoclyps commented Jun 21, 2021

Initial spike of python-gitlab looks good:

import os

import gitlab

# implement as config
GITLAB_TOKEN = os.getenv("GITLAB_TOKEN")
GITLAB_USER = os.getenv("GITLAB_USER")
GITLAB_URL = os.getenv("GITLAB_URL", "https://gitlab.com")
GITLAB_REPOSITORY = "3601513:gitterHQ/webapp"
GITLAB_DEFAULT_PAGE_SIZE = 100

repository_id = GITLAB_REPOSITORY.split(":")[0]

# implement as client
# private token or personal token authentication
client = gitlab.Gitlab(url=GITLAB_URL, private_token=GITLAB_TOKEN)
project = client.projects.get(id=repository_id)
requests = project.mergerequests.list(state="opened", order_by="created_at", sort="asc")

# implement as domain model for `PullRequest`.
for request in requests:
    print(request.author["username"])
    print(request.created_at)
    print(request.merge_status)
    print(request.web_url)
    print(request.title)
    print(request.updated_at)
    print(" ")

Example pull request reponse

{
      "title":"Fix anonymous token leak",
      "updated_at":"2020-09-02T17:20:10.829Z",
      "upvotes":0,
      "user_notes_count":3,
      "web_url":"https://gitlab.com/gitterHQ/webapp/-/merge_requests/1068",
      "work_in_progress":false
   },
   "_module":"<module""gitlab.v4.objects.merge_requests""from""/Users/kyle/.pyenv/versions/3.9.4/lib/python3.9/site-packages/gitlab/v4/objects/merge_requests.py"">",
   "_parent_attrs":{
      "project_id":3601513
   },
   "_updated_attrs":{
      
   },
   "approval_rules":<gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalRuleManager object at 0x108bbf760>,
   "approvals":<gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalManager object at 0x108bbfbe0>,
   "awardemojis":<gitlab.v4.objects.award_emojis.ProjectMergeRequestAwardEmojiManager object at 0x108bbf9d0>,
   "diffs":<gitlab.v4.objects.merge_requests.ProjectMergeRequestDiffManager object at 0x108bbf9a0>,
   "discussions":<gitlab.v4.objects.discussions.ProjectMergeRequestDiscussionManager object at 0x108bbfb80>,
   "manager":<gitlab.v4.objects.merge_requests.ProjectMergeRequestManager object at 0x108b8ccd0>,
   "notes":<gitlab.v4.objects.notes.ProjectMergeRequestNoteManager object at 0x108bbfc40>,
   "resourcelabelevents":<gitlab.v4.objects.events.ProjectMergeRequestResourceLabelEventManager object at 0x108bbfd00>,
   "resourcemilestoneevents":<gitlab.v4.objects.events.ProjectMergeRequestResourceMilestoneEventManager object at 0x108bbfcd0>,
   "resourcestateevents":<gitlab.v4.objects.events.ProjectMergeRequestResourceStateEventManager object at 0x108bbf8b0>
}

@apoclyps apoclyps added enhancement New feature or request python Pull requests that update Python code labels Jun 21, 2021
@apoclyps
Copy link
Owner

apoclyps commented Jun 24, 2021

a rough implementation has been implemented in #192

there are a number of todos around refactoring the existing codebase to make it reusable with other source control providers but it's looking promising. the only feature that is not strictly compatible is the lack of an addition/deletion diff on Gitlab merge requests.

image

@apoclyps apoclyps changed the title Gitlab/Bitbutcket feature flag? [Feature] Add support for Gitlab Jun 26, 2021
@apoclyps
Copy link
Owner

apoclyps commented Jun 26, 2021

#192 has been merged to master and will be available in release 3.0.0: https://pypi.org/project/reviews/#files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Pull requests that update Python code
Projects
None yet
Development

No branches or pull requests

2 participants