Skip to content

Commit 2306ec3

Browse files
tarekbadrshafrittoli
authored andcommitted
add repository event
1 parent 8ebd273 commit 2306ec3

File tree

4 files changed

+151
-31
lines changed

4 files changed

+151
-31
lines changed

cli/cdevents/cli/__main__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
from cdevents.cli.pipelinerun import finished as pipe_finished
1919
from cdevents.cli.pipelinerun import queued as pipe_queued
2020
from cdevents.cli.pipelinerun import started as pipe_started
21+
from cdevents.cli.repository import created as repo_created
22+
from cdevents.cli.repository import deleted as repo_deleted
23+
from cdevents.cli.repository import modified as repo_modified
2124
from cdevents.cli.service import deployed as service_deployed
2225
from cdevents.cli.service import removed as service_removed
2326
from cdevents.cli.service import rolledback as service_rolledback
@@ -81,6 +84,14 @@ def pipelinerun():
8184
pipelinerun.add_command(pipe_finished)
8285
pipelinerun.add_command(pipe_queued)
8386

87+
@click.group(help=add_disclaimer_text("""Commands Repository related CloudEvent."""))
88+
def repository():
89+
"""Click group for command 'repository'."""
90+
91+
repository.add_command(repo_created)
92+
repository.add_command(repo_modified)
93+
repository.add_command(repo_deleted)
94+
8495

8596
@click.group(help=add_disclaimer_text("""Commands Service related CloudEvent."""))
8697
def service():
@@ -119,6 +130,7 @@ def cli():
119130
cli.add_command(branch)
120131
cli.add_command(env)
121132
cli.add_command(pipelinerun)
133+
cli.add_command(repository)
122134
cli.add_command(service)
123135
cli.add_command(taskrun)
124136

cli/cdevents/cli/repository.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""Module for cli repository commands."""
2+
from __future__ import annotations
3+
4+
import os
5+
from typing import List
6+
7+
import click
8+
9+
from cdevents.cli.utils import add_disclaimer_text, print_function_args
10+
from cdevents.cli.cdevents_command import CDeventsCommand
11+
12+
from cdevents.core.events import Events
13+
from cdevents.core import event_type
14+
15+
# pylint: disable=unused-argument
16+
def common_repository_options(function):
17+
"""Decorator for common cli options for repository."""
18+
function = click.option(
19+
"--id",
20+
"-i",
21+
required=False,
22+
type=str,
23+
help="Repository Id.",
24+
)(function)
25+
function = click.option(
26+
"--name",
27+
"-n",
28+
required=False,
29+
type=str,
30+
help="Repository's Name.",
31+
)(function)
32+
function = click.option(
33+
"--url",
34+
"-u",
35+
required=False,
36+
type=str,
37+
help="Repository's URL.",
38+
)(function)
39+
function = click.option(
40+
"--data",
41+
"-d",
42+
required=False,
43+
type=(str, str),
44+
multiple=True,
45+
help="Repository's Data.",
46+
)(function)
47+
48+
return function
49+
50+
51+
@click.command(help=add_disclaimer_text("Repository Created CloudEvent."))
52+
@common_repository_options
53+
def created(
54+
id: str,
55+
name: str = None,
56+
url: str = None,
57+
data: List[str] = None,
58+
):
59+
print_function_args()
60+
e = Events()
61+
new_event = e.create_repository_event(event_type.RepositoryCreatedEventV1, id, name, url, data)
62+
cdevents_command = CDeventsCommand()
63+
cdevents_command.run(new_event)
64+
65+
66+
@click.command(help=add_disclaimer_text("Repository Modified CloudEvent."))
67+
@common_repository_options
68+
def modified(
69+
id: str,
70+
name: str = None,
71+
url: str = None,
72+
data: List[str] = None,
73+
):
74+
print_function_args()
75+
e = Events()
76+
new_event = e.create_repository_event(event_type.RepositoryModifiedEventV1, id, name, url, data)
77+
cdevents_command = CDeventsCommand()
78+
cdevents_command.run(new_event)
79+
80+
81+
@click.command(help=add_disclaimer_text("Repository Deleted CloudEvent."))
82+
@common_repository_options
83+
def deleted(
84+
id: str,
85+
name: str = None,
86+
url: str = None,
87+
data: List[str] = None,
88+
):
89+
print_function_args()
90+
e = Events()
91+
new_event = e.create_repository_event(event_type.RepositoryModifiedEventV1, id, name, url, data)
92+
cdevents_command = CDeventsCommand()
93+
cdevents_command.run(new_event)
94+

core/cdevents/core/event_type.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
"""Constants Event types."""
22

3-
# PipelineRun events
4-
PipelineRunStartedEventV1 :str = "cd.pipelinerun.started.v1"
5-
PipelineRunFinishedEventV1 :str = "cd.pipelinerun.finished.v1"
6-
PipelineRunQueuedEventV1 :str = "cd.pipelinerun.queued.v1"
7-
8-
# TaskRun events
9-
TaskRunStartedEventV1 :str = "cd.taskrun.started.v1"
10-
TaskRunFinishedEventV1 :str = "cd.taskrun.finished.v1"
11-
12-
# Repository events
13-
RepositoryCreatedEventV1 :str = "cd.repository.created.v1"
14-
RepositoryModifiedEventV1 :str = "cd.repository.modified.v1"
15-
RepositoryDeletedEventV1 :str = "cd.repository.deleted.v1"
3+
# Artifact Events
4+
ArtifactPackagedEventV1 :str = "cd.artifact.packaged.v1"
5+
ArtifactPublishedEventV1 :str = "cd.artifact.published.v1"
166

177
# Branch Events
188
BranchCreatedEventV1 :str = "cd.repository.branch.created.v1"
199
BranchDeletedEventV1 :str = "cd.repository.branch.deleted.v1"
2010

11+
# Build Events
12+
BuildStartedEventV1 :str = "cd.build.started.v1"
13+
BuildQueuedEventV1 :str = "cd.build.queued.v1"
14+
BuildFinishedEventV1 :str = "cd.build.finished.v1"
15+
2116
# Change Events
2217
ChangeCreatedEventV1 :str = "cd.repository.change.created.v1"
2318
ChangeUpdatedEventV1 :str = "cd.repository.change.updated.v1"
2419
ChangeReviewedEventV1 :str = "cd.repository.change.reviewed.v1"
2520
ChangeMergedEventV1 :str = "cd.repository.change.merged.v1"
2621
ChangeAbandonedEventV1 :str = "cd.repository.change.abandoned.v1"
2722

28-
# Build Events
29-
BuildStartedEventV1 :str = "cd.build.started.v1"
30-
BuildQueuedEventV1 :str = "cd.build.queued.v1"
31-
BuildFinishedEventV1 :str = "cd.build.finished.v1"
32-
33-
# Test Events
34-
TestCaseStartedEventV1 :str = "cd.test.case.started.v1"
35-
TestCaseQueuedEventV1 :str = "cd.test.case.queued.v1"
36-
TestCaseFinishedEventV1 :str = "cd.test.case.finished.v1"
37-
38-
TestSuiteStartedEventV1 :str = "cd.test.suite.started.v1"
39-
TestSuiteQueuedEventV1 :str = "cd.test.suite.queued.v1"
40-
TestSuiteFinishedEventV1 :str = "cd.test.suite.finished.v1"
41-
42-
# Artifact Events
43-
ArtifactPackagedEventV1 :str = "cd.artifact.packaged.v1"
44-
ArtifactPublishedEventV1 :str = "cd.artifact.published.v1"
45-
4623
# Environment Events
4724
EnvironmentCreatedEventV1 :str = "cd.environment.created.v1"
4825
EnvironmentModifiedEventV1 :str = "cd.environment.modified.v1"
4926
EnvironmentDeletedEventV1 :str = "cd.environment.deleted.v1"
5027

28+
# PipelineRun events
29+
PipelineRunStartedEventV1 :str = "cd.pipelinerun.started.v1"
30+
PipelineRunFinishedEventV1 :str = "cd.pipelinerun.finished.v1"
31+
PipelineRunQueuedEventV1 :str = "cd.pipelinerun.queued.v1"
32+
33+
# Repository events
34+
RepositoryCreatedEventV1 :str = "cd.repository.created.v1"
35+
RepositoryModifiedEventV1 :str = "cd.repository.modified.v1"
36+
RepositoryDeletedEventV1 :str = "cd.repository.deleted.v1"
37+
5138
# Service Events
5239
ServiceDeployedEventV1 :str = "cd.service.deployed.v1"
5340
ServiceUpgradedEventV1 :str = "cd.service.upgraded.v1"
5441
ServiceRolledbackEventV1 :str = "cd.service.rolledback.v1"
5542
ServiceRemovedEventV1 :str = "cd.service.removed.v1"
5643

44+
# TaskRun events
45+
TaskRunStartedEventV1 :str = "cd.taskrun.started.v1"
46+
TaskRunFinishedEventV1 :str = "cd.taskrun.finished.v1"
47+
48+
# Test Events
49+
TestCaseStartedEventV1 :str = "cd.test.case.started.v1"
50+
TestCaseQueuedEventV1 :str = "cd.test.case.queued.v1"
51+
TestCaseFinishedEventV1 :str = "cd.test.case.finished.v1"
52+
53+
TestSuiteStartedEventV1 :str = "cd.test.suite.started.v1"
54+
TestSuiteQueuedEventV1 :str = "cd.test.suite.queued.v1"
55+
TestSuiteFinishedEventV1 :str = "cd.test.suite.finished.v1"

core/cdevents/core/events.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ def create_pipelinerun_event(self, event_type: str , id: str, name: str, status:
9090

9191
return event
9292

93+
def create_repository_event(self, event_type: str , id: str, name: str, url: str, data = {}) -> CloudEvent:
94+
"""Create repository event.
95+
"""
96+
97+
extensions = {
98+
"repositoryid": id,
99+
"repositoryname": name,
100+
"repositoryurl": url,
101+
}
102+
103+
event = self.create_event(event_type, extensions, data)
104+
105+
return event
106+
107+
93108
def create_service_event(self, event_type: str , envid: str, name: str, version: str, data = {}) -> CloudEvent:
94109
"""Create service event.
95110
"""

0 commit comments

Comments
 (0)