mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Added support for the Self-Hosted actions runners API (#1684)
* Added data model for Self-Hosted Actions Runner * Added function for getting self-hosted runners
This commit is contained in:
@@ -125,6 +125,7 @@ import github.PullRequest
|
||||
import github.Referrer
|
||||
import github.Repository
|
||||
import github.RepositoryKey
|
||||
import github.SelfHostedActionsRunner
|
||||
import github.SourceImport
|
||||
import github.Stargazer
|
||||
import github.StatsCodeFrequency
|
||||
@@ -2788,6 +2789,33 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
self._requester, headers, data, completed=True
|
||||
)
|
||||
|
||||
def get_self_hosted_runner(self, runner_id):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/runners/:id <https://docs.github.com/en/rest/reference/actions#get-a-self-hosted-runner-for-a-repository`_
|
||||
:param runner_id: int
|
||||
:rtype: :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner`
|
||||
"""
|
||||
assert isinstance(runner_id, int), runner_id
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET", self.url + "/actions/runners/" + str(runner_id)
|
||||
)
|
||||
return github.SelfHostedActionsRunner.SelfHostedActionsRunner(
|
||||
self._requester, headers, data, completed=True
|
||||
)
|
||||
|
||||
def get_self_hosted_runners(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/runners <https://docs.github.com/en/rest/reference/actions#list-self-hosted-runners-for-a-repository`_
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.SelfHostedActionsRunner.SelfHostedActionsRunner,
|
||||
self._requester,
|
||||
self.url + "/actions/runners",
|
||||
None,
|
||||
list_item="runners",
|
||||
)
|
||||
|
||||
def get_source_import(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/import <https://developer.github.com/v3/migration/source_imports/#get-import-progress>`_
|
||||
@@ -3354,6 +3382,24 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
"DELETE", self.url + "/collaborators/" + collaborator
|
||||
)
|
||||
|
||||
def remove_self_hosted_runner(self, runner):
|
||||
"""
|
||||
:calls: `DELETE /repos/:owner/:repo/actions/runners/:runner_id <https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository>`_
|
||||
:param runner: int or :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner`
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(
|
||||
runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner
|
||||
) or isinstance(runner, int), runner
|
||||
|
||||
if isinstance(runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner):
|
||||
runner = runner.id
|
||||
|
||||
status, _, _ = self._requester.requestJson(
|
||||
"DELETE", self.url + "/actions/runners/" + str(runner)
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `POST /hub <http://developer.github.com/>`_
|
||||
|
||||
@@ -38,6 +38,7 @@ from github.PullRequest import PullRequest
|
||||
from github.PullRequestComment import PullRequestComment
|
||||
from github.Referrer import Referrer
|
||||
from github.RepositoryKey import RepositoryKey
|
||||
from github.SelfHostedActionsRunner import SelfHostedActionsRunner
|
||||
from github.SourceImport import SourceImport
|
||||
from github.Stargazer import Stargazer
|
||||
from github.StatsCodeFrequency import StatsCodeFrequency
|
||||
@@ -371,6 +372,8 @@ class Repository(CompletableGithubObject):
|
||||
def get_release(self, id: Union[int, str]) -> GitRelease: ...
|
||||
def get_release_asset(self, id: int) -> GitReleaseAsset: ...
|
||||
def get_releases(self) -> PaginatedList[GitRelease]: ...
|
||||
def get_self_hosted_runner(self, runner_id: int) -> SelfHostedActionsRunner: ...
|
||||
def get_self_hosted_runners(self) -> PaginatedList[SelfHostedActionsRunner]: ...
|
||||
def get_source_import(self) -> SourceImport: ...
|
||||
def get_stargazers(self) -> PaginatedList[NamedUser]: ...
|
||||
def get_stargazers_with_dates(self) -> PaginatedList[Stargazer]: ...
|
||||
@@ -478,6 +481,7 @@ class Repository(CompletableGithubObject):
|
||||
def remove_from_collaborators(
|
||||
self, collaborator: Union[str, NamedUser]
|
||||
) -> None: ...
|
||||
def remove_self_hosted_runner(self, runner: Union[SelfHostedActionsRunner, int]) -> bool: ...
|
||||
def remove_invitation(self, invite_id: int) -> None: ...
|
||||
def replace_topics(self, topics: List[str]) -> None: ...
|
||||
@property
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2020 Victor Zeng <zacker150@hotmail.com> #
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
# #
|
||||
# PyGithub is free software: you can redistribute it and/or modify it under #
|
||||
# the terms of the GNU Lesser General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public License #
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import github.GithubObject
|
||||
|
||||
|
||||
class SelfHostedActionsRunner(github.GithubObject.NonCompletableGithubObject):
|
||||
"""
|
||||
This class represents Self-hosted GitHub Actions Runners. The reference can be found at
|
||||
https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#self-hosted-runners
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
return self.get__repr__({"name": self._name.value})
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
:type: int
|
||||
"""
|
||||
return self._id.value
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
return self._name.value
|
||||
|
||||
@property
|
||||
def os(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
return self._os.value
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
"""
|
||||
:type: str
|
||||
"""
|
||||
return self._status.value
|
||||
|
||||
@property
|
||||
def busy(self):
|
||||
"""
|
||||
:type: bool
|
||||
"""
|
||||
return self._busy.value
|
||||
|
||||
def labels(self):
|
||||
"""
|
||||
:type: list of dicts
|
||||
"""
|
||||
return self._labels.value
|
||||
|
||||
def _initAttributes(self):
|
||||
self._id = github.GithubObject.NotSet
|
||||
self._name = github.GithubObject.NotSet
|
||||
self._os = github.GithubObject.NotSet
|
||||
self._status = github.GithubObject.NotSet
|
||||
self._busy = github.GithubObject.NotSet
|
||||
self._labels = []
|
||||
|
||||
def _useAttributes(self, attributes):
|
||||
if "id" in attributes: # pragma no branch
|
||||
self._id = self._makeIntAttribute(attributes["id"])
|
||||
if "name" in attributes: # pragma no branch
|
||||
self._name = self._makeStringAttribute(attributes["name"])
|
||||
if "os" in attributes: # pragma no branch
|
||||
self._os = self._makeStringAttribute(attributes["os"])
|
||||
if "status" in attributes: # pragma no branch
|
||||
self._status = self._makeStringAttribute(attributes["status"])
|
||||
if "busy" in attributes:
|
||||
self._busy = self._makeBoolAttribute(attributes["busy"])
|
||||
if "labels" in attributes:
|
||||
self._labels = self._makeListOfDictsAttribute(attributes["labels"])
|
||||
@@ -0,0 +1,19 @@
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
from github.GithubObject import NonCompletableGithubObject
|
||||
|
||||
class SelfHostedActionsRunner(NonCompletableGithubObject):
|
||||
def __repr__(self) -> str: ...
|
||||
def _initAttributes(self) -> None: ...
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
@property
|
||||
def os(self) -> str: ...
|
||||
@property
|
||||
def status(self) -> str: ...
|
||||
@property
|
||||
def busy(self) -> bool: ...
|
||||
def labels(self) -> List[Dict[str, Union[str, int]]]: ...
|
||||
Reference in New Issue
Block a user