| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ea8c4c2 commit f8283ae
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,9 +9,11 @@ CLI examples | |||
| 9 | 9 | CI Lint | |
| 10 | 10 | ------- | |
| 11 | 11 | ||
| 12 | + **ci-lint has been Removed in Gitlab 16, use project-ci-lint instead** | ||
| 13 | + | ||
| 12 | 14 | Lint a CI YAML configuration from a string: | |
| 13 | 15 | ||
| 14 | - .. note:: | ||
| 16 | + .. note:: | ||
| 15 | 17 | ||
| 16 | 18 | To see output, you will need to use the ``-v``/``--verbose`` flag. | |
| 17 | 19 | ||
@@ -39,6 +41,9 @@ Validate a CI YAML configuration from a file (lints and exits with non-zero on f | |||
| 39 | 41 | ||
| 40 | 42 | $ gitlab ci-lint validate --content @.gitlab-ci.yml | |
| 41 | 43 | ||
| 44 | + Project CI Lint | ||
| 45 | + --------------- | ||
| 46 | + | ||
| 42 | 47 | Lint a project's CI YAML configuration: | |
| 43 | 48 | ||
| 44 | 49 | .. code-block:: console | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,13 @@ | |||
| 1 | + from datetime import date | ||
| 2 | + | ||
| 3 | + | ||
| 1 | 4 | def test_project_deploy_tokens(gl, project): | |
| 5 | + today = date.today().isoformat() | ||
| 2 | 6 | deploy_token = project.deploytokens.create( | |
| 3 | 7 | { | |
| 4 | 8 | "name": "foo", | |
| 5 | 9 | "username": "bar", | |
| 6 | - "expires_at": "2022-01-01", | ||
| 10 | + "expires_at": today, | ||
| 7 | 11 | "scopes": ["read_registry"], | |
| 8 | 12 | } | |
| 9 | 13 | ) | |
@@ -12,7 +16,7 @@ def test_project_deploy_tokens(gl, project): | |||
| 12 | 16 | ||
| 13 | 17 | deploy_token = project.deploytokens.get(deploy_token.id) | |
| 14 | 18 | assert deploy_token.name == "foo" | |
| 15 | - assert deploy_token.expires_at == "2022-01-01T00:00:00.000Z" | ||
| 19 | + assert deploy_token.expires_at == today + "T00:00:00.000Z" | ||
| 16 | 20 | assert deploy_token.scopes == ["read_registry"] | |
| 17 | 21 | assert deploy_token.username == "bar" | |
| 18 | 22 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,15 +10,15 @@ def test_groups(gl): | |||
| 10 | 10 | "email": "user@test.com", | |
| 11 | 11 | "username": "user", | |
| 12 | 12 | "name": "user", | |
| 13 | - "password": "user_pass", | ||
| 13 | + "password": "E4596f8be406Bc3a14a4ccdb1df80587", | ||
| 14 | 14 | } | |
| 15 | 15 | ) | |
| 16 | 16 | user2 = gl.users.create( | |
| 17 | 17 | { | |
| 18 | 18 | "email": "user2@test.com", | |
| 19 | 19 | "username": "user2", | |
| 20 | 20 | "name": "user2", | |
| 21 | - "password": "user2_pass", | ||
| 21 | + "password": "E4596f8be406Bc3a14a4ccdb1df80587$2", | ||
| 22 | 22 | } | |
| 23 | 23 | ) | |
| 24 | 24 | group1 = gl.groups.create( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ def test_merge_requests(project): | |||
| 16 | 16 | } | |
| 17 | 17 | ) | |
| 18 | 18 | ||
| 19 | - source_branch = "branch1" | ||
| 19 | + source_branch = "branch-merge-request-api" | ||
| 20 | 20 | project.branches.create({"branch": source_branch, "ref": "main"}) | |
| 21 | 21 | ||
| 22 | 22 | project.files.create( | |
@@ -28,7 +28,7 @@ def test_merge_requests(project): | |||
| 28 | 28 | } | |
| 29 | 29 | ) | |
| 30 | 30 | project.mergerequests.create( | |
| 31 | - {"source_branch": "branch1", "target_branch": "main", "title": "MR readme2"} | ||
| 31 | + {"source_branch": source_branch, "target_branch": "main", "title": "MR readme2"} | ||
| 32 | 32 | ) | |
| 33 | 33 | ||
| 34 | 34 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ def test_create_user(gl, fixture_dir): | |||
| 13 | 13 | "email": "foo@bar.com", | |
| 14 | 14 | "username": "foo", | |
| 15 | 15 | "name": "foo", | |
| 16 | - "password": "foo_password", | ||
| 16 | + "password": "E4596f8be406Bc3a14a4ccdb1df80587$3", | ||
| 17 | 17 | "avatar": open(fixture_dir / "avatar.png", "rb"), | |
| 18 | 18 | } | |
| 19 | 19 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import json | |
| 2 | + import logging | ||
| 2 | 3 | import time | |
| 3 | 4 | ||
| 4 | 5 | ||
@@ -31,9 +32,13 @@ def test_list_all_commits(gitlab_cli, project): | |||
| 31 | 32 | data = { | |
| 32 | 33 | "branch": "new-branch", | |
| 33 | 34 | "start_branch": "main", | |
| 34 | - "commit_message": "New commit on new branch", | ||
| 35 | + "commit_message": "chore: test commit on new branch", | ||
| 35 | 36 | "actions": [ | |
| 36 | - {"action": "create", "file_path": "new-file", "content": "new content"} | ||
| 37 | + { | ||
| 38 | + "action": "create", | ||
| 39 | + "file_path": "test-cli-repo.md", | ||
| 40 | + "content": "new content", | ||
| 41 | + } | ||
| 37 | 42 | ], | |
| 38 | 43 | } | |
| 39 | 44 | commit = project.commits.create(data) | |
@@ -76,6 +81,19 @@ def test_commit_merge_requests(gitlab_cli, project, merge_request, wait_for_side | |||
| 76 | 81 | """This tests the `project-commit merge-requests` command and also tests | |
| 77 | 82 | that we can print the result using the `json` formatter""" | |
| 78 | 83 | # Merge the MR first | |
| 84 | + wait_for_sidekiq(timeout=60) | ||
| 85 | + | ||
| 86 | + logging.info(f"MR status: {merge_request.state}") | ||
| 87 | + logging.info(f"MR merge status: {merge_request.detailed_merge_status}") | ||
| 88 | + | ||
| 89 | + if merge_request.detailed_merge_status == "not_approved": | ||
| 90 | + logging.info("Approving Merge Request") | ||
| 91 | + | ||
| 92 | + merge_request.approve() | ||
| 93 | + | ||
| 94 | + logging.info(f"MR merge status: {merge_request.detailed_merge_status}") | ||
| 95 | + time.sleep(5) | ||
| 96 | + | ||
| 79 | 97 | merge_result = merge_request.merge(should_remove_source_branch=True) | |
| 80 | 98 | wait_for_sidekiq(timeout=60) | |
| 81 | 99 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - import pytest | ||
| 1 | + from datetime import date | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | def test_list_project_access_tokens(gitlab_cli, project): | |
@@ -18,13 +18,14 @@ def test_create_project_access_token_with_scopes(gitlab_cli, project): | |||
| 18 | 18 | "test-token", | |
| 19 | 19 | "--scopes", | |
| 20 | 20 | "api,read_repository", | |
| 21 | + "--expires-at", | ||
| 22 | + date.today().isoformat(), | ||
| 21 | 23 | ] | |
| 22 | 24 | ret = gitlab_cli(cmd) | |
| 23 | 25 | ||
| 24 | 26 | assert ret.success | |
| 25 | 27 | ||
| 26 | 28 | ||
| 27 | - @pytest.mark.skip(reason="Requires GitLab 14.7") | ||
| 28 | 29 | def test_list_group_access_tokens(gitlab_cli, group): | |
| 29 | 30 | cmd = ["group-access-token", "list", "--group-id", group.id] | |
| 30 | 31 | ret = gitlab_cli(cmd) | |
@@ -42,6 +43,8 @@ def test_create_group_access_token_with_scopes(gitlab_cli, group): | |||
| 42 | 43 | "test-token", | |
| 43 | 44 | "--scopes", | |
| 44 | 45 | "api,read_repository", | |
| 46 | + "--expires-at", | ||
| 47 | + date.today().isoformat(), | ||
| 45 | 48 | ] | |
| 46 | 49 | ret = gitlab_cli(cmd) | |
| 47 | 50 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,6 @@ | |||
| 1 | + from datetime import date | ||
| 2 | + | ||
| 3 | + | ||
| 1 | 4 | def test_create_user_impersonation_token_with_scopes(gitlab_cli, user): | |
| 2 | 5 | cmd = [ | |
| 3 | 6 | "user-impersonation-token", | |
@@ -8,6 +11,8 @@ def test_create_user_impersonation_token_with_scopes(gitlab_cli, user): | |||
| 8 | 11 | "test-token", | |
| 9 | 12 | "--scopes", | |
| 10 | 13 | "api,read_user", | |
| 14 | + "--expires-at", | ||
| 15 | + date.today().isoformat(), | ||
| 11 | 16 | ] | |
| 12 | 17 | ret = gitlab_cli(cmd) | |
| 13 | 18 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | + import logging | ||
| 1 | 2 | import os | |
| 2 | 3 | import time | |
| 4 | + from datetime import date | ||
| 5 | + | ||
| 6 | + branch = "branch-cli-v4" | ||
| 3 | 7 | ||
| 4 | 8 | ||
| 5 | 9 | def test_create_project(gitlab_cli): | |
@@ -22,28 +26,6 @@ def test_update_project(gitlab_cli, project): | |||
| 22 | 26 | assert description in ret.stdout | |
| 23 | 27 | ||
| 24 | 28 | ||
| 25 | - def test_create_ci_lint(gitlab_cli, valid_gitlab_ci_yml): | ||
| 26 | - cmd = ["ci-lint", "create", "--content", valid_gitlab_ci_yml] | ||
| 27 | - ret = gitlab_cli(cmd) | ||
| 28 | - | ||
| 29 | - assert ret.success | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - def test_validate_ci_lint(gitlab_cli, valid_gitlab_ci_yml): | ||
| 33 | - cmd = ["ci-lint", "validate", "--content", valid_gitlab_ci_yml] | ||
| 34 | - ret = gitlab_cli(cmd) | ||
| 35 | - | ||
| 36 | - assert ret.success | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - def test_validate_ci_lint_invalid_exits_non_zero(gitlab_cli, invalid_gitlab_ci_yml): | ||
| 40 | - cmd = ["ci-lint", "validate", "--content", invalid_gitlab_ci_yml] | ||
| 41 | - ret = gitlab_cli(cmd) | ||
| 42 | - | ||
| 43 | - assert not ret.success | ||
| 44 | - assert "CI YAML Lint failed (Invalid configuration format)" in ret.stderr | ||
| 45 | - | ||
| 46 | - | ||
| 47 | 29 | def test_validate_project_ci_lint(gitlab_cli, project, valid_gitlab_ci_yml): | |
| 48 | 30 | cmd = [ | |
| 49 | 31 | "project-ci-lint", | |
@@ -103,7 +85,7 @@ def test_create_user(gitlab_cli, gl): | |||
| 103 | 85 | email = "fake@email.com" | |
| 104 | 86 | username = "user1" | |
| 105 | 87 | name = "User One" | |
| 106 | - password = "fakepassword" | ||
| 88 | + password = "E4596f8be406Bc3a14a4ccdb1df80587" | ||
| 107 | 89 | ||
| 108 | 90 | cmd = [ | |
| 109 | 91 | "user", | |
@@ -215,8 +197,6 @@ def test_create_issue_note(gitlab_cli, issue): | |||
| 215 | 197 | ||
| 216 | 198 | ||
| 217 | 199 | def test_create_branch(gitlab_cli, project): | |
| 218 | - branch = "branch1" | ||
| 219 | - | ||
| 220 | 200 | cmd = [ | |
| 221 | 201 | "project-branch", | |
| 222 | 202 | "create", | |
@@ -233,7 +213,6 @@ def test_create_branch(gitlab_cli, project): | |||
| 233 | 213 | ||
| 234 | 214 | ||
| 235 | 215 | def test_create_merge_request(gitlab_cli, project): | |
| 236 | - branch = "branch1" | ||
| 237 | 216 | ||
| 238 | 217 | cmd = [ | |
| 239 | 218 | "project-merge-request", | |
@@ -257,23 +236,43 @@ def test_accept_request_merge(gitlab_cli, project, wait_for_sidekiq): | |||
| 257 | 236 | mr = project.mergerequests.list()[0] | |
| 258 | 237 | file_data = { | |
| 259 | 238 | "branch": mr.source_branch, | |
| 260 | - "file_path": "README2", | ||
| 239 | + "file_path": "test-cli-v4.md", | ||
| 261 | 240 | "content": "Content", | |
| 262 | - "commit_message": "Pre-merge commit", | ||
| 241 | + "commit_message": "chore: test-cli-v4 change", | ||
| 263 | 242 | } | |
| 264 | 243 | project.files.create(file_data) | |
| 265 | - time.sleep(2) | ||
| 244 | + time.sleep(30) | ||
| 266 | 245 | wait_for_sidekiq(timeout=60) | |
| 267 | 246 | ||
| 268 | - cmd = [ | ||
| 247 | + logging.info(f"MR status: {mr.state}") | ||
| 248 | + logging.info(f"MR merge status: {mr.detailed_merge_status}") | ||
| 249 | + | ||
| 250 | + if mr.detailed_merge_status == "not_approved": | ||
| 251 | + logging.info("Approving Merge Request") | ||
| 252 | + | ||
| 253 | + approve_cmd = [ | ||
| 254 | + "project-merge-request", | ||
| 255 | + "approve", | ||
| 256 | + "--project-id", | ||
| 257 | + project.id, | ||
| 258 | + "--iid", | ||
| 259 | + mr.iid, | ||
| 260 | + ] | ||
| 261 | + gitlab_cli(approve_cmd) | ||
| 262 | + | ||
| 263 | + time.sleep(5) | ||
| 264 | + logging.info(f"MR merge status: {mr.detailed_merge_status}") | ||
| 265 | + | ||
| 266 | + time.sleep(0.5) | ||
| 267 | + approve_cmd = [ | ||
| 269 | 268 | "project-merge-request", | |
| 270 | 269 | "merge", | |
| 271 | 270 | "--project-id", | |
| 272 | 271 | project.id, | |
| 273 | 272 | "--iid", | |
| 274 | 273 | mr.iid, | |
| 275 | 274 | ] | |
| 276 | - ret = gitlab_cli(cmd) | ||
| 275 | + ret = gitlab_cli(approve_cmd) | ||
| 277 | 276 | ||
| 278 | 277 | assert ret.success | |
| 279 | 278 | ||
@@ -501,9 +500,6 @@ def test_delete_project_variable(gitlab_cli, variable): | |||
| 501 | 500 | ||
| 502 | 501 | ||
| 503 | 502 | def test_delete_branch(gitlab_cli, project): | |
| 504 | - # TODO: branch fixture | ||
| 505 | - branch = "branch1" | ||
| 506 | - | ||
| 507 | 503 | cmd = ["project-branch", "delete", "--project-id", project.id, "--name", branch] | |
| 508 | 504 | ret = gitlab_cli(cmd) | |
| 509 | 505 | ||
@@ -590,7 +586,7 @@ def test_create_project_with_values_at_prefixed(gitlab_cli, tmpdir): | |||
| 590 | 586 | def test_create_project_deploy_token(gitlab_cli, project): | |
| 591 | 587 | name = "project-token" | |
| 592 | 588 | username = "root" | |
| 593 | - expires_at = "2021-09-09" | ||
| 589 | + expires_at = date.today().isoformat() | ||
| 594 | 590 | scopes = "read_registry" | |
| 595 | 591 | ||
| 596 | 592 | cmd = [ | |
@@ -666,7 +662,7 @@ def test_delete_project_deploy_token(gitlab_cli, deploy_token): | |||
| 666 | 662 | def test_create_group_deploy_token(gitlab_cli, group): | |
| 667 | 663 | name = "group-token" | |
| 668 | 664 | username = "root" | |
| 669 | - expires_at = "2021-09-09" | ||
| 665 | + expires_at = date.today().isoformat() | ||
| 670 | 666 | scopes = "read_registry" | |
| 671 | 667 | ||
| 672 | 668 | cmd = [ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments