Skip to content

Commit

Permalink
Merge pull request #479 from lachmanfrantisek/gitlab-project-exists
Browse files Browse the repository at this point in the history
Implement project.exists for GitLab

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 14, 2020
2 parents 9663477 + a526e11 commit f6af906
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,14 @@ def __init__(self, repo: str, service: GitService, namespace: str) -> None:
self.repo = repo
self.namespace = namespace

def exists(self) -> bool:
"""
Check the existence of the repo.
:return: True if the project exists, False otherwise
"""
raise NotImplementedError()

def is_private(self) -> bool:
"""
Is this repo private (accessible only by users with permissions)
Expand Down
11 changes: 10 additions & 1 deletion ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing import List, Optional, Dict, Set, Union

import gitlab
from gitlab.v4.objects import Project as GitlabObjectsProject
from gitlab.v4.objects import GitlabGetError, Project as GitlabObjectsProject

from ogr.abstract import (
PullRequest,
Expand Down Expand Up @@ -120,6 +120,15 @@ def _construct_fork_project(self) -> Optional["GitlabProject"]:
logger.debug(f"Project {self.repo}/{user_login} does not exist: {ex}")
return None

def exists(self) -> bool:
try:
_ = self.gitlab_repo
return True
except GitlabGetError as ex:
if "404 Project Not Found" in str(ex):
return False
raise GitlabAPIException from ex

def is_private(self) -> bool:
"""
Is this repo private? (accessible only by users with granted access)
Expand Down
2 changes: 1 addition & 1 deletion ogr/services/pagure/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def get_fork(self, create: bool = True) -> Optional["PagureProject"]:
return None
return self._construct_fork_project()

def exists(self):
def exists(self) -> bool:
response = self._call_project_api_raw()
return response.ok

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
_requre:
DataTypes: 1
key_strategy: StorageKeysInspectSimple
version_storage_file: 2
requests.sessions:
send:
GET:
https://gitlab.com/api/v4/projects/packit-service%2Fogr-tests:
- metadata:
latency: 0.4326820373535156
module_call_list:
- unittest.main
- teamcity.unittestpy
- unittest.runner
- unittest.suite
- unittest.case
- requre.online_replacing
- test_generic_commands
- ogr.services.gitlab.project
- gitlab.exceptions
- gitlab.mixins
- gitlab
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
_links:
events: https://gitlab.com/api/v4/projects/14233409/events
issues: https://gitlab.com/api/v4/projects/14233409/issues
labels: https://gitlab.com/api/v4/projects/14233409/labels
members: https://gitlab.com/api/v4/projects/14233409/members
merge_requests: https://gitlab.com/api/v4/projects/14233409/merge_requests
repo_branches: https://gitlab.com/api/v4/projects/14233409/repository/branches
self: https://gitlab.com/api/v4/projects/14233409
allow_merge_on_skipped_pipeline: null
approvals_before_merge: 0
archived: false
auto_cancel_pending_pipelines: enabled
auto_devops_deploy_strategy: continuous
auto_devops_enabled: false
autoclose_referenced_issues: true
avatar_url: null
build_coverage_regex: null
build_git_strategy: fetch
build_timeout: 3600
builds_access_level: enabled
can_create_merge_request_in: true
ci_config_path: null
ci_default_git_depth: 50
compliance_frameworks: []
container_registry_enabled: true
created_at: '2019-09-10T10:28:09.946Z'
creator_id: 433670
default_branch: master
description: Testing repository for python-ogr package. | https://github.com/packit-service/ogr
emails_disabled: null
empty_repo: false
external_authorization_classification_label: ''
forking_access_level: enabled
forks_count: 4
http_url_to_repo: https://gitlab.com/packit-service/ogr-tests.git
id: 14233409
import_error: null
import_status: none
issues_access_level: enabled
issues_enabled: true
jobs_enabled: true
last_activity_at: '2020-10-12T10:27:00.646Z'
lfs_enabled: true
marked_for_deletion_at: null
marked_for_deletion_on: null
merge_method: merge
merge_requests_access_level: enabled
merge_requests_enabled: true
mirror: false
name: ogr-tests
name_with_namespace: packit-service / ogr-tests
namespace:
avatar_url: /uploads/-/system/group/avatar/6032704/packit-logo.png
full_path: packit-service
id: 6032704
kind: group
name: packit-service
parent_id: null
path: packit-service
web_url: https://gitlab.com/groups/packit-service
only_allow_merge_if_all_discussions_are_resolved: false
only_allow_merge_if_pipeline_succeeds: false
open_issues_count: 57
packages_enabled: true
pages_access_level: enabled
path: ogr-tests
path_with_namespace: packit-service/ogr-tests
permissions:
group_access:
access_level: 50
notification_level: 3
project_access: null
printing_merge_request_link_enabled: true
public_jobs: true
readme_url: https://gitlab.com/packit-service/ogr-tests/-/blob/master/README.md
remove_source_branch_after_merge: null
repository_access_level: enabled
request_access_enabled: false
resolve_outdated_diff_discussions: false
runners_token: VjGdzzwZbsTY37sxUeWL
service_desk_address: incoming+packit-service-ogr-tests-14233409-issue-@incoming.gitlab.com
service_desk_enabled: true
shared_runners_enabled: true
shared_with_groups: []
snippets_access_level: enabled
snippets_enabled: true
ssh_url_to_repo: [email protected]:packit-service/ogr-tests.git
star_count: 0
suggestion_commit_message: null
tag_list: []
visibility: public
web_url: https://gitlab.com/packit-service/ogr-tests
wiki_access_level: enabled
wiki_enabled: true
_next: null
elapsed: 0.2
encoding: null
headers:
CF-Cache-Status: DYNAMIC
CF-RAY: 5e1fede9dc4327a0-PRG
Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Fri, 01 Nov 2019 13-36-03 GMT
Etag: W/"8fa6c889a7a81210afaac7009d5f98fa"
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
GitLab-LB: fe-10-lb-gprd
GitLab-SV: localhost
RateLimit-Limit: '600'
RateLimit-Observed: '6'
RateLimit-Remaining: '594'
RateLimit-Reset: '1602664192'
RateLimit-ResetTime: Wed, 14 Oct 2020 08:29:52 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: cloudflare
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
Vary: Accept-Encoding, Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: jbWNNpu98k5
X-Runtime: '0.076490'
cf-request-id: 05c7d30626000027a0ba910200000001
raw: !!binary ""
reason: OK
status_code: 200
https://gitlab.com/api/v4/user:
- metadata:
latency: 0.4252171516418457
module_call_list:
- unittest.main
- teamcity.unittestpy
- unittest.runner
- unittest.suite
- unittest.case
- requre.online_replacing
- test_generic_commands
- ogr.services.gitlab.project
- ogr.services.gitlab.service
- gitlab
- gitlab.exceptions
- gitlab.mixins
- gitlab
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 2
_content:
avatar_url: https://assets.gitlab-static.net/uploads/-/system/user/avatar/433670/avatar.png
bio: ''
bio_html: ''
can_create_group: true
can_create_project: true
color_scheme_id: 5
confirmed_at: '2016-03-01T11:08:34.779Z'
created_at: '2016-03-01T11:08:00.390Z'
current_sign_in_at: '2020-09-14T09:21:53.853Z'
email: [email protected]
external: false
extra_shared_runners_minutes_limit: null
id: 433670
identities: []
job_title: ''
last_activity_on: '2020-10-14'
last_sign_in_at: '2020-09-07T09:53:44.736Z'
linkedin: ''
location: ''
name: "Franti\u0161ek Lachman"
organization: ''
private_profile: false
projects_limit: 100000
public_email: [email protected]
shared_runners_minutes_limit: 2000
skype: ''
state: active
theme_id: 2
twitter: ''
two_factor_enabled: true
username: lachmanfrantisek
web_url: https://gitlab.com/lachmanfrantisek
website_url: lachman.tk
work_information: null
_next: null
elapsed: 0.2
encoding: null
headers:
CF-Cache-Status: DYNAMIC
CF-RAY: 5e1fede3cba727a0-PRG
Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Fri, 01 Nov 2019 13-36-03 GMT
Etag: W/"e5fffd1b75a481aa7959b34bc1c7b3b4"
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
GitLab-LB: fe-10-lb-gprd
GitLab-SV: localhost
RateLimit-Limit: '600'
RateLimit-Observed: '5'
RateLimit-Remaining: '595'
RateLimit-Reset: '1602664191'
RateLimit-ResetTime: Wed, 14 Oct 2020 08:29:51 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: cloudflare
Set-Cookie: __cfduid=d36a65c61db92895ecc95a0d067bb7bca1602664131; expires=Fri,
13-Nov-20 08:28:51 GMT; path=/; domain=.gitlab.com; HttpOnly; SameSite=Lax;
Secure
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
Vary: Accept-Encoding, Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: IWwJIg1d4i
X-Runtime: '0.029543'
cf-request-id: 05c7d3025a000027a0ba8d6200000001
raw: !!binary ""
reason: OK
status_code: 200
Loading

0 comments on commit f6af906

Please sign in to comment.