Skip to content

Commit

Permalink
Merge pull request #95 from con/manual
Browse files Browse the repository at this point in the history
Add "manual" event type
  • Loading branch information
yarikoptic committed Jun 11, 2021
2 parents 0f13cf6 + f2dd0aa commit b4f1a5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
24 changes: 14 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ keys:
``cron``
A build run on a schedule

``manual``
A build trigger manually by a human or through the CI system's API

``pr``
A build in response to activity on a pull request

Expand Down Expand Up @@ -286,7 +289,7 @@ A sample config file:
accountName: mih
projectSlug: datalad
since: 2021-01-20T00:00:00Z
types: [cron, pr, push]
types: [cron, manual, pr, push]
secrets:
github: '\b(v1\.)?[a-f0-9]{40}\b'
docker-hub: '\b[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}\b'
Expand Down Expand Up @@ -324,15 +327,16 @@ Placeholder Definition
release was published
``{ci}`` The name of the CI system (``github``, ``travis``, or
``appveyor``)
``{type}`` The event type that triggered the build (``cron``, ``pr``,
or ``push``), or ``release`` for GitHub releases
``{type_id}`` Further information on the triggering event; for ``cron``,
this is a timestamp for the start of the build; for
``pr``, this is the number of the associated pull request,
or ``UNK`` if it cannot be determined; for ``push``, this
is the name of the branch to which the push was made (or
possibly the tag that was pushed, if using Appveyor); for
``release``, this is the name of the tag
``{type}`` The event type that triggered the build (``cron``,
``manual``, ``pr``, or ``push``), or ``release`` for
GitHub releases
``{type_id}`` Further information on the triggering event; for ``cron``
and ``manual``, this is a timestamp for the start of the
build; for ``pr``, this is the number of the associated
pull request, or ``UNK`` if it cannot be determined; for
``push``, this is the name of the branch to which the push
was made (or possibly the tag that was pushed, if using
Appveyor); for ``release``, this is the name of the tag
``{build_commit}`` The hash of the commit the build ran against or that was
tagged for the release. Note that, for PR builds on
Travis and Appveyor, this is the hash of an autogenerated
Expand Down
4 changes: 4 additions & 0 deletions src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class EventType(Enum):
CRON = "cron"
PUSH = "push"
PULL_REQUEST = "pr"
MANUAL = "manual"

@classmethod
def from_gh_event(cls, gh_event: str) -> Optional["EventType"]:
return {
"schedule": cls.CRON,
"push": cls.PUSH,
"pull_request": cls.PULL_REQUEST,
"workflow_dispatch": cls.MANUAL,
"repository_dispatch": cls.MANUAL,
}.get(gh_event)

@classmethod
Expand All @@ -53,6 +56,7 @@ def from_travis_event(cls, travis_event: str) -> Optional["EventType"]:
"cron": cls.CRON,
"push": cls.PUSH,
"pull_request": cls.PULL_REQUEST,
"api": cls.MANUAL,
}.get(travis_event)


Expand Down
2 changes: 1 addition & 1 deletion src/tinuous/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_build_assets(
log.info("Event type is %r; skipping", run.event)

def get_event_id(self, run: WorkflowRun, event_type: EventType) -> str:
if event_type is EventType.CRON:
if event_type in (EventType.CRON, EventType.MANUAL):
return ensure_aware(run.created_at).strftime("%Y%m%dT%H%M%S")
elif event_type is EventType.PUSH:
return run.head_branch
Expand Down
4 changes: 2 additions & 2 deletions src/tinuous/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_build_assets(
log.info("Event type is %r; skipping", build["event_type"])

def get_commit(self, build: Dict[str, Any], event_type: EventType) -> Optional[str]:
if event_type in (EventType.CRON, EventType.PUSH):
if event_type in (EventType.CRON, EventType.MANUAL, EventType.PUSH):
commit = build["commit"]["sha"]
assert isinstance(commit, str)
return commit
Expand Down Expand Up @@ -150,7 +150,7 @@ def from_job(
) -> "TravisJobLog":
created_at = isoparse(build["started_at"])
event_id: str
if event_type is EventType.CRON:
if event_type in (EventType.CRON, EventType.MANUAL):
event_id = created_at.strftime("%Y%m%dT%H%M%S")
elif event_type is EventType.PUSH:
event_id = build["branch"]["name"]
Expand Down

0 comments on commit b4f1a5e

Please sign in to comment.