Skip to content

Commit

Permalink
Codeberg (Forgejo) support.
Browse files Browse the repository at this point in the history
No code changes, just test and documentation.
  • Loading branch information
lhupfeldt committed Jan 22, 2025
1 parent e0fc745 commit 6dbddda
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 74 deletions.
18 changes: 17 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,23 @@ Test

.. note::

To run the GitHub folder job test a GitHub test repository is needed! TODO: Describe the setup.
To run the Codeberg folder job test a `Codeberg <https://codeberg.org/>`_ test and Jenkins configuration repository is needed!

Fork `codeberg test repo <https://codeberg.org/lhupfeldt/jenkinsflow-org-job-test>`_ to your own organization/user account.
Add the `Gitea plugin <https://plugins.jenkins.io/gitea/>`_ to Jenkins. In system config add a Gitea server name `Codeberg`, URL `https://codeberg.org/`.
Add an `Organization Folder` job named `codeberg-org`, with server `Codeberg`. Set `owner` to your organization/account and
`Script path` to `Jenkinsfile.jenkinsflow-test`.

.. note::

To run the GitHub folder job test a `GitHub <https://github.com/>`_ test and Jenkins configuration repository is needed!

Fork `github test repo <https://github.com/lhupfeldt/jenkinsflow-org-job-test>`_ to your own organization/user account.
Add a GitHub App in your organization and install it on the repo.
Create the corresponfig GitHubApp credentilal in Jennkins, id `cred-github-jenkinsflow-test`.
Add the `Gitea plugin <https://plugins.jenkins.io/gitea/>`_ to Jenkins. In system config add a Gitea server name `GitHub`, URL `https://github.com/`.
Add an `Organization Folder` job named `github-org`, with server `GitHub`. Set `owner` to your organization/account, credential
to `cred-github-jenkinsflow-test` and `Script path` to `Jenkinsfile.jenkinsflow-test`.

#. Run the tests using ``nox``::

Expand Down
4 changes: 2 additions & 2 deletions src/jenkins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
# Initial query
# Build a three level query to handle github organization folder jobs.
# Note that 'name' in response does not contain first 'job/' from url, but does contain intermediate 'job/', so:
# 'name': 'gh-org/job/jenkinsflow-gh-folder-test/job/main'
# 'name': 'github-org-jenkinsflow-test/job/jenkinsflow-gh-folder-test/job/main'
# Corresponds:
# 'url': 'http://<host>:<port>/job/gh-org/job/jenkinsflow-gh-folder-test/job/main'
# 'url': 'http://<host>:<port>/job/github-org-jenkinsflow-test/job/jenkinsflow-gh-folder-test/job/main'
_ONE_LEVEL_JOBS_INFO_QUERY = f"jobs[name,{_GIVEN_JOB_QUERY_WITH_PARAM_DEFS}_RECURSE_]"
_TWO_LEVELS_JOBS_INFO_QUERY = _ONE_LEVEL_JOBS_INFO_QUERY.replace("_RECURSE_", "," + _ONE_LEVEL_JOBS_INFO_QUERY)
_THREE_LEVELS_JOBS_INFO_QUERY = _TWO_LEVELS_JOBS_INFO_QUERY.replace("_RECURSE_", "," + _ONE_LEVEL_JOBS_INFO_QUERY)
Expand Down
3 changes: 2 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def filter_items_by_api_type(item):
return

# We must have an ApiType in name now, since api_type fixture was used
current_item_api = ApiType[item_api_type_regex.match(item.name).groups()[0]]
api_type_name, _, _ = (item_api_type_regex.match(item.name).groups()[0]).partition("-") # TODO, this cannot be the way to get api_type
current_item_api = ApiType[api_type_name]
if current_item_api not in selected_api_types:
print(f"{':'.join(str(place) for place in item.location)} DESELECTED ({current_item_api} not in {selected_api_types})")
deselected.append(item)
Expand Down
68 changes: 0 additions & 68 deletions test/github_folder_test.py

This file was deleted.

6 changes: 4 additions & 2 deletions test/invalid_job_names_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@


@pytest.mark.apis(ApiType.JENKINS)
def test_invalid_job_in_gh_folder_name(api_type):
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_invalid_job_in_org_folder_name(api_type, org_name):
url = "http://localhost:8080"
api = JenkinsApi(url)
with pytest.raises(InvalidJobNameException):
with serial(api, timeout=20, report_interval=1) as ctrl1:
ctrl1.invoke("gh-org/job/jenkinsflow-gh-folder-test/job/main")
# Name must not contain '/job/'
ctrl1.invoke(f"{org_name}/job/jenkinsflow-gh-folder-test/job/main")
73 changes: 73 additions & 0 deletions test/organization_folder_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2024 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.

from datetime import datetime

import pytest

from jenkinsflow.flow import serial


from .framework.cfg import ApiType
from .framework import api_select


@pytest.mark.apis(ApiType.JENKINS)
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_org_folder_build_branch(api_type, org_name):
with api_select.api(__file__, api_type, existing_jobs=True) as api:
api.flow_job()
api.job(f"{org_name}/jenkinsflow-org-job-test/main", max_fails=0, expect_invocations=1, expect_order=1)

with serial(api, timeout=20, report_interval=1) as ctrl1:
ctrl1.invoke(f"{org_name}/jenkinsflow-org-job-test/main")


@pytest.mark.apis(ApiType.JENKINS)
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_org_folder_build_slow_branch(api_type, org_name):
with api_select.api(__file__, api_type, existing_jobs=True) as api:
api.flow_job()
api.job(f"{org_name}/jenkinsflow-org-job-test/slow", max_fails=0, expect_invocations=1, expect_order=1)

before = datetime.now()
with serial(api, timeout=70, report_interval=1) as ctrl1:
ctrl1.invoke(f"{org_name}/jenkinsflow-org-job-test/slow")

# The job sleeps 10s
assert (datetime.now() - before).total_seconds() >= 10


@pytest.mark.apis(ApiType.JENKINS)
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_org_folder_build_with_parameters(api_type, org_name):
with api_select.api(__file__, api_type, existing_jobs=True) as api:
api.flow_job()
api.job(f"{org_name}/jenkinsflow-org-job-test/parameters", max_fails=0, expect_invocations=1, expect_order=1)

with serial(api, timeout=70, report_interval=1) as ctrl1:
ctrl1.invoke(f"{org_name}/jenkinsflow-org-job-test/parameters", GREETING="Hi")


@pytest.mark.apis(ApiType.JENKINS)
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_org_folder_scan_organization(api_type, org_name):
with api_select.api(__file__, api_type, existing_jobs=True) as api:
api.flow_job()
api.job(f"{org_name}", max_fails=0, expect_invocations=1, expect_order=1)

# Scan time depends on the GitHub organization!
with serial(api, timeout=10, report_interval=1) as ctrl1:
ctrl1.invoke(f"{org_name}", assume_finished_after=5)


@pytest.mark.apis(ApiType.JENKINS)
@pytest.mark.parametrize("org_name", ["codeberg-org-jenkinsflow-test", "github-org-jenkinsflow-test"])
def test_org_folder_scan_repo(api_type, org_name):
with api_select.api(__file__, api_type, existing_jobs=True) as api:
api.flow_job()
api.job(f"{org_name}/jenkinsflow-org-job-test", max_fails=0, expect_invocations=1, expect_order=1)

# Repo scan time depends on the GitHub repo, it does not take too long, but can be queued for a while!
with serial(api, timeout=10, report_interval=1) as ctrl1:
ctrl1.invoke(f"{org_name}/jenkinsflow-org-job-test", assume_finished_after=5)

0 comments on commit 6dbddda

Please sign in to comment.