commit c6a97f2ce8e60bc326623849b68f2356d4ea2710
parent e51b53c2090406140ec6f0bd547399702ca7616b
Author: arjoonn <arjoonn@noreply.localhost>
Date: Sat, 25 Mar 2023 07:18:43 +0000
Allow ssh git remotes (!77)
Reviewed-on: https://gitea.midpathsoftware.com/midpath/jaypore_ci/pulls/77
╔ 🟡 : JayporeCI [sha 41d2ff2951]
┏━ build-and-test
┃
┃ 🟢 : JciEnv [2b270ea7] 0:12
┃ 🟢 : Jci [e3ab7fde] 0:17 ❮-- ['JciEnv']
┃ 🟢 : black [ad641ada] 0: 0 ❮-- ['JciEnv']
┃ 🟢 : install-test [6836cba6] 0: 0 ❮-- ['JciEnv']
┃ 🟢 : pylint [d150391b] 0: 8 ❮-- ['JciEnv']
┃ 🟢 : pytest [82d89c26] 0:25 Cov: 89% ❮-- ['JciEnv']
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Publish
┃
┃ 🟢 : DockerHubJci [56a36ae4] 0:57
┃ 🔵 : DockerHubJcienv [9222127b] 0:59
┃ 🟢 : PublishDocs [c7fb9140] 0:47
┃ 🔴 : PublishPypi [c85ecd0d] 0: 5 v0.2.30
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Diffstat:
7 files changed, 83 insertions(+), 39 deletions(-)
diff --git a/docs/source/examples/github_remote.py b/docs/source/examples/github_remote.py
@@ -0,0 +1,8 @@
+from jaypore_ci import jci, repos, remotes
+
+repo = repos.Git.from_env()
+# Specify JAYPORE_GITHUB_TOKEN in your secrets file
+remote = remotes.Github.from_env(repo=repo)
+
+with jci.Pipeline(repo=repo, remote=remote) as p:
+ p.job("Pytest", "pytest ")
diff --git a/docs/source/index.rst b/docs/source/index.rst
@@ -387,6 +387,15 @@ and so you can use anything that is mentioned in that documentation.
:language: python
:linenos:
+Using a github remote
+---------------------
+
+If you want to use github instead of gitea, it's very simple to use.
+
+.. literalinclude:: examples/github_remote.py
+ :language: python
+ :linenos:
+
Contributing
============
@@ -412,28 +421,4 @@ Reference
Changelog
=========
-0.2.29
-------
-
-- 🐞: When gitea token does not have enough scope log correctly and exit
-
-0.2.28
-------
-
-- 🐞: When there are multiple (push) remotes, Jaypore CI will pick the first one and use that.
-
-0.2.27
-------
-
-- 🎁: Jobs older than 1 week will be removed before starting a new pipeline.
-
-0.2.26
-------
-
-- ⚙️: The Dockerfile inside `cicd/Dockerfile` now requires a build arg that specifies the version of Jaypore CI to install.
-
-0.2.25
-------
-
-- 🎁: A dockerfile is now used to send context of the codebase to the docker daemon instead of directly mounting the code. This allows us to easily use remote systems for jobs
diff --git a/jaypore_ci/changelog.py b/jaypore_ci/changelog.py
@@ -13,7 +13,8 @@ version_map = {
"command simply by using the `executor_kwargs` argument while "
"defining the job. Read more in `Passing extra_hosts and other "
"arguments to docker`_."
- )
+ ),
+ f"{NEW}: SSH remotes are now compatible with Jaypore CI.",
],
"instructions": [],
},
diff --git a/jaypore_ci/interfaces.py b/jaypore_ci/interfaces.py
@@ -5,6 +5,8 @@ Currently only gitea and docker are supported as remote and executor
respectively.
"""
from enum import Enum
+from pathlib import Path
+from urllib.parse import urlparse
from typing import NamedTuple, List
@@ -34,6 +36,58 @@ class Status(Enum):
SKIPPED = 70
+class RemoteInfo(NamedTuple):
+ """
+ Holds information about the remote irrespective of if the remote was ssh or
+ https.
+ """
+
+ netloc: str
+ owner: str
+ repo: str
+ original: str
+
+ @classmethod
+ def parse(cls, remote: str) -> "RemoteInfo":
+ """
+ Given a git remote url string, parses and breaks down information
+ contained in the url.
+
+ Works with the following formats:
+
+ ssh://git@gitea.arjoonn.com:arjoonn/jaypore_ci.git
+ ssh+git://git@gitea.arjoonn.com:arjoonn/jaypore_ci.git
+
+ git@gitea.arjoonn.com:arjoonn/jaypore_ci.git
+ git@gitea.arjoonn.com:arjoonn/jaypore_ci.git
+
+ https://gitea.arjoonn.com/midpath/jaypore_ci.git
+ http://gitea.arjoonn.com/midpath/jaypore_ci.git
+ """
+ original = remote
+ if (
+ ("ssh://" in remote or "ssh+git://" in remote or "://" not in remote)
+ and "@" in remote
+ and remote.endswith(".git")
+ ):
+ _, remote = remote.split("@")
+ netloc, path = remote.split(":")
+ owner, repo = path.split("/")
+ return RemoteInfo(
+ netloc=netloc,
+ owner=owner,
+ repo=repo.replace(".git", ""),
+ original=original,
+ )
+ url = urlparse(remote)
+ return RemoteInfo(
+ netloc=url.netloc,
+ owner=Path(url.path).parts[1],
+ repo=Path(url.path).parts[2].replace(".git", ""),
+ original=original,
+ )
+
+
class Repo:
"""
Contains information about the current VCS repo.
diff --git a/jaypore_ci/remotes/gitea.py b/jaypore_ci/remotes/gitea.py
@@ -4,12 +4,10 @@ A gitea remote git host.
This is used to report pipeline status to the remote.
"""
import os
-from pathlib import Path
-from urllib.parse import urlparse
import requests
-from jaypore_ci.interfaces import Remote, RemoteApiFailed, Repo
+from jaypore_ci.interfaces import Remote, RemoteApiFailed, Repo, RemoteInfo
from jaypore_ci.logging import logger
@@ -31,11 +29,11 @@ class Gitea(Remote): # pylint: disable=too-many-instance-attributes
"""
os.environ["JAYPORE_COMMIT_BRANCH"] = repo.branch
os.environ["JAYPORE_COMMIT_SHA"] = repo.sha
- remote = urlparse(repo.remote)
+ rem = RemoteInfo.parse(repo.remote)
return cls(
- root=f"{remote.scheme}://{remote.netloc}",
- owner=Path(remote.path).parts[1],
- repo=Path(remote.path).parts[2].replace(".git", ""),
+ root=f"https://{rem.netloc}",
+ owner=rem.owner,
+ repo=rem.repo,
branch=repo.branch,
token=os.environ["JAYPORE_GITEA_TOKEN"],
sha=repo.sha,
diff --git a/jaypore_ci/remotes/github.py b/jaypore_ci/remotes/github.py
@@ -4,12 +4,10 @@ A github remote git host.
This is used to report pipeline status to the remote.
"""
import os
-from pathlib import Path
-from urllib.parse import urlparse
import requests
-from jaypore_ci.interfaces import Remote, RemoteApiFailed, Repo
+from jaypore_ci.interfaces import Remote, RemoteApiFailed, Repo, RemoteInfo
from jaypore_ci.logging import logger
@@ -36,13 +34,13 @@ class Github(Remote): # pylint: disable=too-many-instance-attributes
- Create a new pull request for that branch
- Allow posting updates using the gitea token provided
"""
- remote = urlparse(repo.remote)
+ rem = RemoteInfo.parse(repo.remote)
os.environ["JAYPORE_COMMIT_BRANCH"] = repo.branch
os.environ["JAYPORE_COMMIT_SHA"] = repo.sha
return cls(
root="https://api.github.com",
- owner=Path(remote.path).parts[1],
- repo=Path(remote.path).parts[2].replace(".git", ""),
+ owner=rem.owner,
+ repo=rem.repo,
branch=repo.branch,
token=os.environ["JAYPORE_GITHUB_TOKEN"],
sha=repo.sha,
diff --git a/pyproject.toml b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jaypore_ci"
-version = "0.2.29"
+version = "0.2.30"
description = ""
authors = ["arjoonn sharma <arjoonn.94@gmail.com>"]
homepage = "https://www.jayporeci.in/"