Skip to content

Commit

Permalink
Refactor the messages to its own file (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
chmouel authored Feb 12, 2025
1 parent 820f44e commit 880c2ec
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 349 deletions.
9 changes: 1 addition & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ repos:
"90",
--wrap-descriptions,
"90",
prow,
pipelines_as_code_prow,
]
- repo: local
hooks:
- id: generated
language: system
name: Check Generated Files
entry: make
args: ["check"]

- repo: local
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .tekton/pipelines/in-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ spec:
- name: PAC_LGTM_REVIEW_EVENT
value: $(params.lgtm_review_event)
script: |
exec python3 prow/prow.py
exec ./pipelines-as-code-prow
workspaces:
- name: source
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM registry.access.redhat.com/ubi9/ubi-minimal

RUN microdnf install python3-requests -y && \
microdnf clean all && \
rm -rf /var/cache/yum

ADD ./prow/prow.py /prow.py

ENTRYPOINT ["python3", "/prow.py"]
RUN mkdir /src
USER 1001
COPY --chown=1001:1001 pipelines-as-code-prow /src
COPY --chown=1001:1001 pipelines_as_code_prow /src/pipelines_as_code_prow
ENTRYPOINT ["python3", "/src/pipelines-as-code-prow"]
26 changes: 4 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,26 @@ PASS_TOKEN = github/chmouel-token
PRURL = https://github.com/$(GH_REPO_OWNER)/$(GH_REPO_NAME)/pull/$(GH_PR_NUM)
CONTAINER_IMAGE = ghcr.io/openshift-pipelines/pipelines-as-code-prow:nightly
PYTEST = uvx --with=requests --with=pytest-cov --with=pytest-sugar pytest
PYTEST_ARGS = --cov=prow --cov-report=term
PYTEST_ARGS = --cov=pipelines_as_code_prow --cov-report=term

# Phony targets
.PHONY: generate test directtest open_pr check help

# Targets with help messages

generate: ## Generate pipeline YAML files
@echo "Generating $(PIPELINE_PROW) 🚿" && \
echo "####### Do not edit this file, use 'make generate'" > $(PIPELINE_PROW) && \
$(UVCMD) ./hack/tekton-task-embed-script.py --using-image=$(CONTAINER_IMAGE) ./prow/base.yaml >> $(PIPELINE_PROW)
.PHONY: test directtest open_pr help

test: ## Run tests with pytest
@$(PYTEST) -v prow $(PYTEST_ARGS) $(ARGS)
@$(PYTEST) -v pipelines_as_code_prow $(PYTEST_ARGS) $(ARGS)

directtest: ## Run a specific command directly (e.g., make directtest CMD=/lgtm)
@[[ -n "$(CMD)" ]] || (echo "Please specify a command to run as argument: like 'make directtest CMD=/lgtm'" && exit 1)
@env GH_PR_NUM=$(GH_PR_NUM) GH_REPO_NAME=$(GH_REPO_NAME) GH_REPO_OWNER=$(GH_REPO_OWNER) \
GH_PR_SENDER=$(GH_PR_SENDER) GH_COMMENT_SENDER=$(GH_COMMENT_SENDER) \
PAC_TRIGGER_COMMENT="$(CMD)" GITHUB_TOKEN=`pass show $(PASS_TOKEN)` \
./prow/prow.py
./pipelines_as_code_prow/prow.py

open_pr: ## Open the PR in the browser
@if type -p xdg-open > /dev/null; then xdg-open $(PRURL); \
elif type -p open > /dev/null; then open $(PRURL); \
else echo "No supported browser opener found (xdg-open or open)"; fi

check: ## Check if the generated prow files are up to date
@tmpfile=$$(mktemp /tmp/check-XXXXXX); \
make -s generate PIPELINE_PROW=$$tmpfile && \
if ! cmp -s $(PIPELINE_PROW) $$tmpfile; then \
echo "Changes are needed in $(PIPELINE_PROW): make sure to modify the prun in prow/ and run 'make generate' before pushing"; \
diff --color=always -u $(PIPELINE_PROW) $$tmpfile; \
rm -f $$tmpfile $$tmpfile2; \
exit 1; \
fi; \
rm -f $$tmpfile

help: ## Display this help message
@python3 -c "import re, sys; \
targets = [m.groups() for m in re.finditer(r'^([a-zA-Z0-9_-]+):.*?## (.*)$$', sys.stdin.read(), re.MULTILINE)]; \
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ project.
You will need to install [uv](https://github.com/astral-sh/uv) and use the
makefile targets.

This project use generated PipelineRun as described
[here](https://blog.chmouel.com/2020/07/28/tekton-yaml-templates-and-script-feature/),
you will need to edit the files in the [prow](./prow) directory and run `make` to regenerate
the main PipelineRun. There is a script that inline it in the [pipeline-prow.yaml](./pipeline-prow.yaml).
That allows to separate the logic from the main PipelineRun and be able to use
your editor properly when editing the code (with linters, lsp, checkers etc..).

Please install the pre-commit hooks by running `pre-commit install` to make sure
your commits include the necessary files.

Expand Down
109 changes: 0 additions & 109 deletions hack/tekton-task-embed-script.py

This file was deleted.

103 changes: 51 additions & 52 deletions pipeline-prow.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
####### Do not edit this file, use 'make generate'
---
apiVersion: tekton.dev/v1
kind: Pipeline
Expand All @@ -7,57 +6,57 @@ metadata:
annotations:
pipelinesascode.tekton.dev/on-comment: |
^/(help|rebase|merge|lgtm|(assign|unassign|label|unlabel)[ ].*)$
pipelinesascode.tekton.dev/max-keep-runs: '5'
pipelinesascode.tekton.dev/max-keep-runs: "5"
spec:
params:
- name: repo_owner
- name: repo_name
- name: pull_request_number
- name: pull_request_sender
- name: comment_sender
- name: git_auth_secret
- name: git_auth_secret_key
default: git-provider-token
- name: trigger_comment
- name: lgtm_permissions
default: admin,write
- name: lgtm_threshold
default: '1'
- name: lgtm_review_event
default: APPROVE
- name: merge_method
default: rebase
- name: repo_owner
- name: repo_name
- name: pull_request_number
- name: pull_request_sender
- name: comment_sender
- name: git_auth_secret
- name: git_auth_secret_key
default: git-provider-token
- name: trigger_comment
- name: lgtm_permissions
default: admin,write
- name: lgtm_threshold
default: "1"
- name: lgtm_review_event
default: APPROVE
- name: merge_method
default: rebase
tasks:
- name: manage-pr
displayName: Manage PR Assignments & Labels
taskSpec:
steps:
- name: manage-pr
image: ghcr.io/openshift-pipelines/pipelines-as-code-prow:nightly
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: $(params.git_auth_secret)
key: $(params.git_auth_secret_key)
- name: GH_REPO_OWNER
value: $(params.repo_owner)
- name: GH_PR_SENDER
value: $(params.pull_request_sender)
- name: GH_REPO_NAME
value: $(params.repo_name)
- name: GH_PR_NUM
value: $(params.pull_request_number)
- name: GH_COMMENT_SENDER
value: $(params.comment_sender)
- name: PAC_TRIGGER_COMMENT
value: |
$(params.trigger_comment)
- name: GH_MERGE_METHOD
value: $(params.merge_method)
- name: PAC_LGTM_THRESHOLD
value: $(params.lgtm_threshold)
- name: PAC_LGTM_PERMISSIONS
value: $(params.lgtm_permissions)
- name: PAC_LGTM_REVIEW_EVENT
value: $(params.lgtm_review_event)
- name: manage-pr
displayName: Manage PR Assignments & Labels
taskSpec:
steps:
- name: manage-pr
image: ghcr.io/openshift-pipelines/pipelines-as-code-prow:nightly
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: $(params.git_auth_secret)
key: $(params.git_auth_secret_key)
- name: GH_REPO_OWNER
value: $(params.repo_owner)
- name: GH_PR_SENDER
value: $(params.pull_request_sender)
- name: GH_REPO_NAME
value: $(params.repo_name)
- name: GH_PR_NUM
value: $(params.pull_request_number)
- name: GH_COMMENT_SENDER
value: $(params.comment_sender)
- name: PAC_TRIGGER_COMMENT
value: |
$(params.trigger_comment)
- name: GH_MERGE_METHOD
value: $(params.merge_method)
- name: PAC_LGTM_THRESHOLD
value: $(params.lgtm_threshold)
- name: PAC_LGTM_PERMISSIONS
value: $(params.lgtm_permissions)
- name: PAC_LGTM_REVIEW_EVENT
value: $(params.lgtm_review_event)
7 changes: 7 additions & 0 deletions pipelines-as-code-prow
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# Author: Chmouel Boudjnah <[email protected]>

from pipelines_as_code_prow import prow

if __name__ == "__main__":
prow.main()
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 880c2ec

Please sign in to comment.