Add support for workflow dispatch event (#1625)

* Add support for workflow dispatch event

Fixes: #1624
This commit is contained in:
Mahesh Raju
2020-07-30 16:43:05 +10:00
committed by GitHub
parent 136a3e8008
commit 16850ef1ed
7 changed files with 264 additions and 1 deletions
+27
View File
@@ -106,6 +106,33 @@ class Workflow(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._badge_url)
return self._badge_url.value
def create_dispatch(self, ref, inputs=github.GithubObject.NotSet):
"""
:calls: `POST /repos/:owner/:repo/actions/workflows/:workflow_id/dispatches`_
:param ref: :class:`github.Branch.Branch` or :class:`github.Tag.Tag` or :class:`github.Commit.Commit` or string
:param inputs: dict
:rtype: bool
"""
assert (
isinstance(ref, github.Branch.Branch)
or isinstance(ref, github.Tag.Tag)
or isinstance(ref, github.Commit.Commit)
or isinstance(ref, str)
), ref
assert inputs is github.GithubObject.NotSet or isinstance(inputs, dict), inputs
if isinstance(ref, github.Branch.Branch):
ref = ref.name
elif isinstance(ref, github.Commit.Commit):
ref = ref.sha
elif isinstance(ref, github.Tag.Tag):
ref = ref.name
if inputs is github.GithubObject.NotSet:
inputs = {}
status, _, _ = self._requester.requestJson(
"POST", self.url + "/dispatches", input={"ref": ref, "inputs": inputs}
)
return status == 204
def get_runs(
self,
actor=github.GithubObject.NotSet,
+8 -1
View File
@@ -2,21 +2,28 @@ from datetime import datetime
from typing import Any, Dict, Union
from github.Branch import Branch
from github.Commit import Commit
from github.GithubObject import CompletableGithubObject, _NotSetType
from github.NamedUser import NamedUser
from github.PaginatedList import PaginatedList
from github.Tag import Tag
from github.WorkflowRun import WorkflowRun
class Workflow(CompletableGithubObject):
def __repr__(self) -> str: ...
def _initAttributes(self) -> None: ...
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
def create_dispatch(
self,
ref: Union[str, Branch, Commit, Tag],
inputs: Union[Dict[str, Union[str, int, float]], _NotSetType],
) -> bool: ...
def get_runs(
self,
actor: Union[str, NamedUser, _NotSetType],
branch: Union[str, Branch, _NotSetType],
event: Union[str, _NotSetType],
status: Union[str, _NotSetType]
status: Union[str, _NotSetType],
) -> PaginatedList[WorkflowRun]: ...
@property
def id(self) -> int: ...
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+31
View File
@@ -81,3 +81,34 @@ class Workflow(Framework.TestCase):
lambda r: r.id,
[109950033, 108817672, 108794468, 107927403, 105213061, 105212023],
)
def testCreateDispatchWithBranch(self):
dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"}
workflow = self.g.get_repo("wrecker/PyGithub").get_workflow(
"manual_dispatch.yml"
)
branch = self.g.get_repo("wrecker/PyGithub").get_branch(
"workflow_dispatch_branch"
)
self.assertTrue(workflow.create_dispatch(branch, dispatch_inputs))
def testCreateDispatchWithTag(self):
dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"}
workflow = self.g.get_repo("wrecker/PyGithub").get_workflow(
"manual_dispatch.yml"
)
tags = self.g.get_repo("wrecker/PyGithub").get_tags()
tag = [t for t in tags if t.name == "workflow_dispatch_tag"].pop()
self.assertTrue(workflow.create_dispatch(tag, dispatch_inputs))
def testCreateDispatchWithString(self):
dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"}
workflow = self.g.get_repo("wrecker/PyGithub").get_workflow(
"manual_dispatch.yml"
)
ref_str = "main"
self.assertTrue(workflow.create_dispatch(ref_str, dispatch_inputs))
def testCreateDispatchForNonTriggerEnabled(self):
workflow = self.g.get_repo("wrecker/PyGithub").get_workflow("check.yml")
self.assertFalse(workflow.create_dispatch("main"))