Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: add api integration test for ci_cd_token allowlist#2797

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
48726fd
chore(deps): update all non-major dependencies
renovate[bot]Jan 26, 2024
f59aee3
chore(deps): update dependency black to v24
renovate[bot]Jan 29, 2024
4e68d32
chore: adapt style for black v24
nejchJan 29, 2024
7ec3189
fix(cli): allow exclusive arguments as optional (#2770)
SjordJan 29, 2024
d2be1f7
chore(deps): update codecov/codecov-action action to v4
renovate[bot]Feb 5, 2024
7dc2fa6
chore(deps): update all non-major dependencies
renovate[bot]Feb 5, 2024
3501716
chore: update version of `black` for `pre-commit`
JohnVillalovosFeb 5, 2024
35d2aec
chore(deps): update dependency pytest-docker to v3
renovate[bot]Feb 5, 2024
253babb
chore(deps): update dependency pytest to v8
renovate[bot]Feb 5, 2024
f6fd02d
chore(deps): update dependency furo to v2024
renovate[bot]Feb 5, 2024
c631eeb
docs(artifacts): Fix argument indentation
maxnoeFeb 8, 2024
9440a32
fix(api): update manual job status when playing it
1aceFeb 4, 2024
a867c48
feat(api): allow updating protected branches (#2771)
SjordFeb 10, 2024
3c4b27e
chore(deps): update all non-major dependencies
renovate[bot]Feb 12, 2024
e11d889
chore(deps): update python-semantic-release/python-semantic-release a…
renovate[bot]Feb 12, 2024
9596e09
feat(job_token_scope): support job token access allowlist API
nejchJan 19, 2024
4203bec
test: add api integration test for ci_cd_token allowlist
TimKnight-DWPFeb 13, 2024
e2cae65
test: skip in Gitlab 15
TimKnight-DWPFeb 14, 2024
44a354a
Merge branch 'feat/job-token-scope-allowlist' into feat/job-token-sco…
TimKnight-DWPMar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion.github/workflows/docs.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,7 +34,7 @@ jobs:
TOXENV: docs
run: tox
- name: Archive generated docs
uses: actions/upload-artifact@v4.1.0
uses: actions/upload-artifact@v4.3.1
with:
name: html-docs
path: build/sphinx/html/
Expand Down
2 changes: 1 addition & 1 deletion.github/workflows/release.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ jobs:

- name: Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@v8.7.2
uses: python-semantic-release/python-semantic-release@v9.0.3
with:
github_token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

Expand Down
8 changes: 4 additions & 4 deletions.github/workflows/test.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,7 +78,7 @@ jobs:
TOXENV: ${{ matrix.toxenv }}
run: tox -- --override-ini='log_cli=True'
- name: Upload codecov coverage
uses: codecov/codecov-action@v3.1.4
uses: codecov/codecov-action@v4.0.1
with:
files: ./coverage.xml
flags: ${{ matrix.toxenv }}
Expand All@@ -100,7 +100,7 @@ jobs:
TOXENV: cover
run: tox
- name: Upload codecov coverage
uses: codecov/codecov-action@v3.1.4
uses: codecov/codecov-action@v4.0.1
with:
files: ./coverage.xml
flags: unit
Expand All@@ -119,7 +119,7 @@ jobs:
pip install -r requirements-test.txt
- name: Build package
run: python -m build -o dist/
- uses: actions/upload-artifact@v4.1.0
- uses: actions/upload-artifact@v4.3.1
with:
name: dist
path: dist
Expand All@@ -133,7 +133,7 @@ jobs:
uses: actions/setup-python@v5.0.0
with:
python-version: '3.12'
- uses: actions/download-artifact@v4.1.1
- uses: actions/download-artifact@v4.1.2
with:
name: dist
path: dist
Expand Down
6 changes: 3 additions & 3 deletions.pre-commit-config.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ default_language_version:

repos:
- repo: https://github.com/psf/black
rev:23.12.1
rev:24.1.1
hooks:
- id: black
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
rev: v3.14.1
hooks:
- id: commitizen
stages: [commit-msg]
Expand DownExpand Up@@ -47,6 +47,6 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/maxbrunet/pre-commit-renovate
rev: 37.131.0
rev: 37.183.0
hooks:
- id: renovate-config-validator
5 changes: 5 additions & 0 deletionsdocs/gl_objects/protected_branches.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,11 @@ Get a single protected branch::

p_branch = project.protectedbranches.get('main')

Update a protected branch:

p_branch.allow_force_push = True
p_branch.save()

Create a protected branch::

p_branch = project.protectedbranches.create({
Expand Down
6 changes: 2 additions & 4 deletionsgitlab/_backends/protocol.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,7 @@

class BackendResponse(Protocol):
@abc.abstractmethod
def __init__(self, response: requests.Response) -> None:
...
def __init__(self, response: requests.Response) -> None: ...


class Backend(Protocol):
Expand All@@ -30,5 +29,4 @@ def http_request(
verify: Optional[Union[bool, str]],
stream: Optional[bool],
**kwargs: Any,
) -> BackendResponse:
...
) -> BackendResponse: ...
1 change: 0 additions & 1 deletiongitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,6 @@


class Gitlab:

"""Represents a GitLab server connection.

Args:
Expand Down
9 changes: 9 additions & 0 deletionsgitlab/v4/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,6 +262,10 @@ def _populate_sub_parser_by_class(
sub_parser_action.add_argument(
f"--{x.replace('_', '-')}", required=False
)
if mgr_cls._create_attrs.exclusive:
group = sub_parser_action.add_mutually_exclusive_group()
for x in mgr_cls._create_attrs.exclusive:
group.add_argument(f"--{x.replace('_', '-')}")

if action_name == "update":
if cls._id_attr is not None:
Expand All@@ -280,6 +284,11 @@ def _populate_sub_parser_by_class(
f"--{x.replace('_', '-')}", required=False
)

if mgr_cls._update_attrs.exclusive:
group = sub_parser_action.add_mutually_exclusive_group()
for x in mgr_cls._update_attrs.exclusive:
group.add_argument(f"--{x.replace('_', '-')}")

if cls.__name__ in cli.custom_actions:
name = cls.__name__
for action_name in cli.custom_actions[name]:
Expand Down
3 changes: 2 additions & 1 deletiongitlab/v4/objects/artifacts.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/job_artifacts.html
"""

from typing import Any, Callable, Iterator, Optional, TYPE_CHECKING, Union

import requests
Expand DownExpand Up@@ -61,7 +62,7 @@ def download(

Args:
ref_name: Branch or tag name in repository. HEAD or SHA references
are not supported.
are not supported.
job: The name of the job.
job_token: Job token for multi-project pipeline triggers.
streamed: If True the data will be processed by chunks of
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/audit_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/audit_events.html
"""

from typing import Any, cast, Union

from gitlab.base import RESTManager, RESTObject
Expand Down
13 changes: 10 additions & 3 deletionsgitlab/v4/objects/branches.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
from typing import Any, cast, Union

from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
from gitlab.mixins import (
CRUDMixin,
NoUpdateMixin,
ObjectDeleteMixin,
SaveMixin,
UpdateMethod,
)
from gitlab.types import RequiredOptional

__all__ = [
Expand All@@ -28,11 +34,11 @@ def get(
return cast(ProjectBranch, super().get(id=id, lazy=lazy, **kwargs))


class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
class ProjectProtectedBranch(SaveMixin,ObjectDeleteMixin, RESTObject):
_id_attr = "name"


class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
class ProjectProtectedBranchManager(CRUDMixin, RESTManager):
_path = "/projects/{project_id}/protected_branches"
_obj_cls = ProjectProtectedBranch
_from_parent_attrs = {"project_id": "id"}
Expand All@@ -49,6 +55,7 @@ class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
"code_owner_approval_required",
),
)
_update_method = UpdateMethod.PATCH

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/deployments.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/deployments.html
"""

from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union

from gitlab import cli
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/features.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/features.html
"""

from typing import Any, Optional, TYPE_CHECKING, Union

from gitlab import exceptions as exc
Expand Down
1 change: 0 additions & 1 deletiongitlab/v4/objects/job_token_scope.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,6 @@
)
from gitlab.types import RequiredOptional


__all__ = [
"ProjectJobTokenScope",
"ProjectJobTokenScopeManager",
Expand Down
5 changes: 4 additions & 1 deletiongitlab/v4/objects/jobs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,10 @@ def play(self, **kwargs: Any) -> None:
GitlabJobPlayError: If the job could not be triggered
"""
path = f"{self.manager.path}/{self.encoded_id}/play"
self.manager.gitlab.http_post(path, **kwargs)
result = self.manager.gitlab.http_post(path, **kwargs)
if TYPE_CHECKING:
assert isinstance(result, dict)
self._update_attrs(result)

@cli.register_custom_action("ProjectJob")
@exc.on_http_error(exc.GitlabJobEraseError)
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/merge_requests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
https://docs.gitlab.com/ee/api/merge_requests.html
https://docs.gitlab.com/ee/api/merge_request_approvals.html
"""

from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union

import requests
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/projects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/projects.html
"""

from typing import (
Any,
Callable,
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/repositories.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@

Currently this module only contains repository-related methods for projects.
"""

from typing import Any, Callable, Dict, Iterator, List, Optional, TYPE_CHECKING, Union

import requests
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/secure_files.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ee/api/secure_files.html
"""

from typing import Any, Callable, cast, Iterator, Optional, TYPE_CHECKING, Union

import requests
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/users.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
https://docs.gitlab.com/ee/api/users.html
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
"""

from typing import Any, cast, Dict, List, Optional, Union

import requests
Expand Down
1 change: 1 addition & 0 deletionsgitlab/v4/objects/variables.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
https://docs.gitlab.com/ee/api/project_level_variables.html
https://docs.gitlab.com/ee/api/group_level_variables.html
"""

from typing import Any, cast, Union

from gitlab.base import RESTManager, RESTObject
Expand Down
2 changes: 1 addition & 1 deletionrequirements-docker.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
-r requirements.txt
-r requirements-test.txt
pytest-docker==2.0.1
pytest-docker==3.1.1
2 changes: 1 addition & 1 deletionrequirements-docs.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
-r requirements.txt
furo==2023.9.10
furo==2024.1.29
jinja2==3.1.3
myst-parser==2.0.0
sphinx==7.2.6
Expand Down
10 changes: 5 additions & 5 deletionsrequirements-lint.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
-r requirements.txt
argcomplete==2.0.0
black==23.12.1
commitizen==3.13.0
black==24.1.1
commitizen==3.14.1
flake8==7.0.0
isort==5.13.2
mypy==1.8.0
pylint==3.0.3
pytest==7.4.4
pytest==8.0.0
responses==0.24.1
types-PyYAML==6.0.12.12
types-requests==2.31.0.20240106
types-setuptools==69.0.0.20240106
types-requests==2.31.0.20240125
types-setuptools==69.0.0.20240125
2 changes: 1 addition & 1 deletionrequirements-precommit.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
pre-commit==3.6.0
pre-commit==3.6.1
4 changes: 2 additions & 2 deletionsrequirements-test.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
-r requirements.txt
build==1.0.3
coverage==7.4.0
coverage==7.4.1
pytest-console-scripts==1.4.1
pytest-cov==4.1.0
pytest-github-actions-annotate-failures==0.2.0
pytest==7.4.4
pytest==8.0.0
PyYaml==6.0.1
responses==0.24.1
wheel==0.42.0
1 change: 1 addition & 0 deletionstests/functional/api/test_keys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
GitLab API:
https://docs.gitlab.com/ce/api/keys.html
"""

import base64
import hashlib

Expand Down
1 change: 1 addition & 0 deletionstests/functional/api/test_packages.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
https://docs.gitlab.com/ce/api/packages.html
https://docs.gitlab.com/ee/user/packages/generic_packages
"""

from collections.abc import Iterator

from gitlab.v4.objects import GenericPackage
Expand Down
50 changes: 50 additions & 0 deletionstests/functional/api/test_project_job_token_scope.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
import pytest


# TODO: can be enabled when https://github.com/python-gitlab/python-gitlab/pull/2790 merged
@pytest.mark.xfail(reason="project job_token_scope api only in 16.*")
def test_add_project_to_job_token_scope_allowlist(gl, project):
project_to_add = gl.projects.create({"name": "Ci_Cd_token_add_proj"})

scope = project.job_token_scope.get()
resp = scope.allowlist.create({"target_project_id": project_to_add.id})

assert resp.source_project_id == project.id
assert resp.target_project_id == project_to_add.id

project_to_add.delete()


@pytest.mark.xfail(reason="project job_token_scope api only in 16.*")
def test_projects_job_token_scope_allowlist_contains_added_project_name(gl, project):
scope = project.job_token_scope.get()
assert len(scope.allowlist.list()) == 0

project_name = "Ci_Cd_token_named_proj"
project_to_add = gl.projects.create({"name": project_name})
scope.allowlist.create({"target_project_id": project_to_add.id})

scope.refresh()
assert any(allowed.name == project_name for allowed in scope.allowlist.list())

project_to_add.delete()


@pytest.mark.xfail(reason="project job_token_scope api only in 16.*")
def test_remove_project_by_id_from_projects_job_token_scope_allowlist(gl, project):
scope = project.job_token_scope.get()
assert len(scope.allowlist.list()) == 0

project_to_add = gl.projects.create({"name": "Ci_Cd_token_remove_proj"})

scope.allowlist.create({"target_project_id": project_to_add.id})

scope.refresh()
assert len(scope.allowlist.list()) != 0

scope.allowlist.remove(project_to_add.id)

scope.refresh()
assert len(scope.allowlist.list()) == 0

project_to_add.delete()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp