Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 21:33

    nejch on graphql

    feat: add basic GraphQL support… (compare)

  • 21:26
    nejch ready_for_review #2407
  • 21:24
    nejch commented #2408
  • 20:49
    lmilbaum commented #2408
  • 17:01
    nejch opened #2408
  • 17:01

    nejch on requests-toolbelt-deprecation-warning

    fix(deps): bump requests-toolbe… (compare)

  • 16:51
    nejch opened #2407
  • 16:50

    nejch on faq-common-errors

    docs(faq): describe and group c… (compare)

  • 10:58
    nejch commented #2401
  • 10:43
    nejch labeled #2401
  • 10:42
    nejch labeled #2401
  • 10:41
    nejch commented #2402
  • 10:20
    nejch labeled #2402
  • 10:20

    nejch on main

    feat: add resource iteration ev… (compare)

  • 10:20
    nejch closed #2393
  • 10:17
    nejch commented #2393
  • 10:13
    nejch review_requested #2397
  • 10:13
    nejch review_requested #2397
  • 10:13
    nejch edited #2397
  • 10:09
    nejch commented #2326
Nejc Habjan
@nejch
Hi @lmilbaum! Sure. I didn't want to interfere with the draft PR. It's great you tried to keep it backwards compatible! But my thinking is it will be too much work to mock both requests and httpx in unit tests (you'd need both responses and respx). I would maybe only run functional tests using both libraries, and get some early feedback from users and then fully switch unit tests with a breaking release and drop requests
We'd also need to override http_request for httpx, as it handles multipart encoding natively I assume and probably a bit differently. So maybe 2 clients make sense as well.
Ages ago I started working on a grapqhl client but havent gotten back to that. But maybe some code in there might be useful if you end up doing something similar. I should get back to that as well..
python-gitlab/python-gitlab@b8ca5ff
Liora Milbaum
@lmilbaum
@nejch Thank you for you feedback. I have come up with a new direction which might be aligned with your thoughts. Could you please take a quick look at - python-gitlab/python-gitlab#2336 ?
Nejc Habjan
@nejch
I think that's generally the direction I had in mind as well, yes! But I think you'll hit more issues down the road due to requests-specific handling of streaming and multipart. Might need to refactor that.
I'll comment in the PR :)
Liora Milbaum
@lmilbaum
Thanks. That would be great.
Nejc Habjan
@nejch
@lmilbaum not sure if you want comments already while it's still in draft. But generally we should keep gl.http_* methods as they're considered public interface (https://python-gitlab.readthedocs.io/en/latest/api-levels.html) and it would be a breaking change otherwise. Even if they're just re-assigned from the client backend. It will also make the PR smaller :)
1 reply
stdedos
@stdedos:matrix.org
[m]

Hello there! I am doing:

...
    ci_commit_sha = os.environ["CI_COMMIT_SHA"]
    mrs_related = project.commits.get(ci_commit_sha).merge_requests()

    if not mrs_related:
        raise ValueError(f"ci_commit_sha '{ci_commit_sha}' has no associated MRs!")

    if len(mrs_related) > 1:
        msg = f"ci_commit_sha '{ci_commit_sha}' has >1 associated MRs: [{csv(mrs_related)}]"
        warnings.warn(msg)

    return mrs_related[0]["iid"]

but, I don't understand why mypy complains that:

error: Value of type "Union[GitlabList, List[Dict[str, Any]]]" is not indexable  [index]
Nejc Habjan
@nejch

@stdedos:matrix.org we still have some work to do to get typing correct for all methods. See if https://github.com/python-gitlab/python-gitlab/issues?q=is%3Aissue+is%3Aopen+label%3Atyping has your issue or open a new one.

For the time being I think you can work around it like this:

from typing import TYPE_CHECKING
# ...
if TYPE_CHECKING:
    assert isinstance(mrs_related, list)

Maybe not just list but you will see what mypy says :)

stdedos
@stdedos:matrix.org
[m]
mypy is happy with it (not exactly as you show it, but dun'matter)

However, "it's not important for me to fix it" (especially by adding "additional statements") - I was wondering "whether I am wrong or not".
As a lot of that code runs directly on a pipeline (and it has a significant dependencies on the pipeline context), I cannot exactly debug it easily/quickly.

Additionally, "once verifying it right" does not mean that this is always the case

With regards to existing issues: "Well, some kinda look-alike, but not quite". I'll just open a new one
stdedos
@stdedos:matrix.org
[m]
Nejc Habjan
@nejch
I think what you're doing is ok. we probably need to add some typing overloads to correctly infer what we are returning either of the two types based on the arguments provided. Not an issue in your code ;) either way should not affect runtime.
Thanks for the issue!
Liora Milbaum
@lmilbaum
@nejch I need some assistance with rebasing PR #2336
Georgy Grigoryev
@georgydexter_gitlab
hi guys, does anyone know why I'm getting "module 'gitlab' has no attribute 'Gitlab'" on the fresh install with poetry?
Georgy Grigoryev
@georgydexter_gitlab
nevermind, there's some conflicts with gitlab project
Shreya Agarwal
@Shreya-7
@nejch do you mind retrying the latest API functional test in #2347? I'm trying to find exactly how one test started breaking after I fixed my linting :)
Shreya Agarwal
@Shreya-7
nvm, a rebase fixed it
Nejc Habjan
@nejch
@lmilbaum do you still need help with the rebase?
1 reply
@Shreya-7 sorry just saw this. sometimes we do have flaky functional tests but looks like it went green ;)
@georgydexter_gitlab hehe yeah.. we have control of the gitlab project on pypi now, I thought we yanked those releases. Glad you figured it out.
Umair Shahid
@UmairShahid_gitlab
hi
wondergrandma
@wondergrandma
@nejch Hi, i am trying to figure out if it is possible to create Directory inside my repo. I couldnt find anything helpful in docs on this.
I need multiple directories in my repo where data will be stored.
Liora Milbaum
@lmilbaum
@nejch @JohnVillalovos Can one of you please add the label ok-to-test on PR #2362?
Nejc Habjan
@nejch
@lmilbaum I've added the label :) not sure if that helps all contributors as we still need org/repo members for that but lets see
7 replies

@wondergrandma git itself does not track directories, so gitlab can't either. https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/gitkeep-push-empty-folders-git-commit

The convention is to create a .gitkeep file in order to create folders, so just create empty files with whatever path you need to achieve the same effect.

Orde Stevanoski
@ostevanoski_gitlab
Is it still possible to update the release notes for an existing tag via this API? it looks like tag.set_release_notes was removed awhile ago, but is there an alternative way I'm missing?
2 replies
Nejc Habjan
@nejch
@lmilbaum I'll have a busy week ahead (both personal and work trips) so not sure I'll be able to take a look at the httpx PR just yet. Just a heads-up, but I might be able to take a look at smaller things!
1 reply
Abhishek Singh
@abhiandthetruth
Hey can anyone help with python-gitlab/python-gitlab#2367. Facing 401 while fetching saml group links. Its a premium feature.
23 replies
I have used the fixture for gitlab premium too!
Moustapha Cheikh
@moustaphacheikh_gitlab
Hello
i'm working on reporting using the api
i will generates reports about projects progress, time usages, estimations ...
any one have scripts in this context that want to share ?
or interested in colaboration ?
wondergrandma
@wondergrandma

Hi, Im trying to get project ID from specific project. This is how I tried to get it:

gl = gitlab.Gitlab(private_token=config.PRIVATE_TOKEN)
projects = gl.projects.list(owned = True ,search='test')
print(projects)

It returned something like this: [<Project id:1234 path_with_namespace:user/test>]
I tried to convert that response to JSON but it wont work.
Is it possible to somehow get only the ID ?

5 replies
ayunwSky
@ayunwSky

Hey!
My python version is: 3.10.5. I'm trying to create a group named "ayunwSky".

git_url = "http://aa.bb.com/"
git_private_token = "xxxxxxxxx"
gl = gitlab.Gitlab(git_url, private_token=git_private_token)
group = gl.groups.create({"name": "ayunwSky", "path": "ayunwSky"})
print(group)

But i got some error:

Traceback (most recent call last):
  File "E:\codes\pythonProject\venv\lib\site-packages\gitlab\exceptions.py", line 337, in wrapped_f
    return f(*args, **kwargs)
  File "E:\codes\pythonProject\venv\lib\site-packages\gitlab\mixins.py", line 300, in create
    server_data = self.gitlab.http_post(path, post_data=data, files=files, **kwargs)
  File "E:\codes\pythonProject\venv\lib\site-packages\gitlab\client.py", line 1015, in http_post
    result = self.http_request(
  File "E:\codes\pythonProject\venv\lib\site-packages\gitlab\client.py", line 798, in http_request
    raise gitlab.exceptions.GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 403: 403 Forbidden

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\codes\pythonProject\gitlab\create_gitlab_projects_v1.1.py", line 104, in <module>
    create_gitlab_group()
  File "E:\codes\pythonProject\gitlab\create_gitlab_projects_v1.1.py", line 73, in create_gitlab_group
    group = gl.groups.create({"name": "ayunwSky", "path": "ayunwSky"})
  File "E:\codes\pythonProject\venv\lib\site-packages\gitlab\exceptions.py", line 339, in wrapped_f
    raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabCreateError: 403: 403 Forbidden

Who one know what's wrong with that?
In gitlab document,i've got this: On GitLab SaaS, you must use the GitLab UI to create groups without a parent group. You cannot use the API to do this.
Is group can not create without parent group by gitlab library?

2 replies
wondergrandma
@wondergrandma
Hello, is it possible to get Commit Hash back after creating file or updating one ?
Rose Howell
@rchowell_gitlab
Is there a way to access the log from a pipeline job? I can find the name of the job-log file using pipeline.jobs.list()[1].artifacts[0]['filename'], but is the log file accessible somehow?
5 replies
Geetika Joshi
@Geetika26joshi
in gitlab i am getting encoding error "-"is interpeted as –
cesaregerbino
@cesaregerbino

Hi! I'm using a CentOS7 virtual machine created in Oracle VirtualBox.

I've installed on it python with sudo yum install python3and then python-gitlab using sudo yum install python-gitlab

I've tried this python code

import gitlab
import os

gl = gitlab.Gitlab(url='https://<my gitab instance>/', private_token='my_token')

def get_projects():
    projects = gl.projects.list(owned=True)
    for project in projects:
        print(project.name)

def main():
    get_projects()

main()

but it doesn't wok and the error is

Traceback (most recent call last):
  File "Test.py", line 1, in <module>
    import gitlab
  File "/media/sf_SharedWithVM/VM-Python/GitLab/gitlab.py", line 6, in <module>
AttributeError: 'module' object has no attribute 'Gitlab'

Any suggestion will be appreciated. Thank you in advance

14 replies
cesaregerbino
@cesaregerbino

Hi! I'm trying to list the last commit date (with some attributes ... ), for each projects in my GitLab instance.

Now I've a Python code that works


import gitlab
import os

gl = gitlab.Gitlab('https://<my_gitlab_instance>/')

#gl.enable_debug()

def get_projects():
    projects = gl.projects.list(Iterator=True)
    for project in projects:
       commits = project.commits.list(per_page=1)
       if len(commits) > 0:
          for commit in commits:
              print("Project name: " + project.name + " - " + "Project url: " + project.web_url + " - " + "Commit: " + commit.title + " - " + "Author: " + commit.author_name + " - " + "Creation date: " + commit.created_at + " - " + "Last activity date: " + project.last_activity_at)


def main():
    get_projects()

main()

My GitLab instance has a very huge number of projects and so I need to paginate: I'd like to use the generator object using
the argument 'iterator=True' for list() on projects using the generator attributes prev_page, next_page, total_pages, ecc ..
but I don't find any documentation / example taht helps me to use it.

Is there any example somewhere or could you tell me how I've to change my code?

Any suggestion will be appreciated and thank you in advance

3 replies
Hadyn van der Berg
@hadyn_gitlab

hello , I'm struggling with the most basic request for projects. using python 3.9:

`

   import gitlab

    self.gl = gitlab.Gitlab(url=settings.config.get('gitlab_base_url'),
                            private_token=settings.config.get('token'),
                            per_page=5)

    projects = self.gl.projects.list(archived=1, visibility="private")

`

and thae projects.list results in a gitlab.exceptions.GitlabHttpError saying
title>Checking your Browser - GitLab</title>
..
<div class="cf-browser-verification cf-im-under-attack">
<noscript>
<h1 style="color:#bd2426;">Please turn JavaScript on and reload the page.</h1>
..
h1>Checking your browser before accessing gitlab.com.</h1>
<div id="no-cookie-warning" class="cookie-warning" style="display:none">
<p style="color:#bd2426;">Please enable Cookies and reload the page</p>

what am I not doing to allow me to login to my private gitlab account and view internal (or private ) projects

2 replies
aka-achea
@aka-achea
dear team, i'm trying to configure group push rule but failed with "AttributeError: 'Group' object has no attribute 'pushrules'"
anyone can help give some advice?
group = gl.groups.get(128654) print(group.name) group.pushrules.create({'deny_delete_tag': True})
1 reply
i'm simply using this