Skip to content

Commit

Permalink
Add /cherry-pick command
Browse files Browse the repository at this point in the history
The command will cherry-pick the PR changes to the target branch upon
merge.

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel authored and pipelines-as-code[bot] committed Feb 13, 2025
1 parent 20181ef commit 2523df5
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[MESSAGES CONTROL]
disable=redefined-outer-name,line-too-long,missing-function-docstring,missing-module-docstring,too-many-locals,invalid-name
disable=redefined-outer-name,line-too-long,missing-function-docstring,missing-module-docstring,too-many-locals,invalid-name,protected-access

4 changes: 2 additions & 2 deletions .tekton/prow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: prow-commands
annotations:
pipelinesascode.tekton.dev/pipeline: ".tekton/pipelines/in-repo.yaml"
pipelinesascode.tekton.dev/on-comment: "^/(rebase|merge|help|lgtm|(assign|unassign|label|unlabel)[ ].*)$"
pipelinesascode.tekton.dev/on-comment: "^/(help|rebase|merge|lgtm|(cherry-pick|assign|unassign|label|unlabel) )"
pipelinesascode.tekton.dev/max-keep-runs: "2"
spec:
params:
Expand All @@ -14,7 +14,7 @@ spec:
- name: revision
value: "{{revision}}"
- name: trigger_comment
value: |-
value: |
{{ trigger_comment }}
- name: repo_owner
value: "{{ repo_owner }}"
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ Pipelines As Code Prow let you trigger Tekton Pipelines based on GitHub comments

The following commands are supported:

| Command | Description |
|-------------------------|------------------------------------------------------------------|
| `/assign user1 user2` | Assigns users for review to the PR |
| `/unassign user1 user2` | Removes assigned users |
| `/label bug feature` | Adds labels to the PR |
| `/unlabel bug feature` | Removes labels from the PR |
| `/lgtm` | Approves the PR if at least 1 org members have commented `/lgtm` |
| `/merge` | Merges the PR if it has enough `/lgtm` approvals |
| `/rebase` | Rebases the PR branch on the base branch |
| `/help` | Shows this help message |
| Command | Description |
|------------------------------|------------------------------------------------------------------|
| `/assign user1 user2` | Assigns users for review to the PR |
| `/unassign user1 user2` | Removes assigned users |
| `/label bug feature` | Adds labels to the PR |
| `/unlabel bug feature` | Removes labels from the PR |
| `/cherry-pick target-branch` | Cherry-picks the PR changes to the target branch on Merges |
| `/lgtm` | Approves the PR if at least 1 org members have commented `/lgtm` |
| `/merge` | Merges the PR if it has enough `/lgtm` approvals |
| `/rebase` | Rebases the PR branch on the base branch |
| `/help` | Shows this help message |

> [!IMPORTANT]
>
> * Please note that multiple comment on the same line are not supported, you need to issue one command per comment.
> * The command needs to be located at the beginning of the comment, if there is any other text before the command it will be ignored.
## Usage

Expand All @@ -32,12 +38,12 @@ metadata:
name: prow-commands
annotations:
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code-prow/refs/heads/main/pipeline-prow.yaml"
pipelinesascode.tekton.dev/on-comment: "^/(help|rebase|merge|lgtm|(assign|unassign|label|unlabel)[ ].*)$"
pipelinesascode.tekton.dev/on-comment: "^/(help|rebase|merge|lgtm|(cherry-pick|assign|unassign|label|unlabel)[ ].*)$"
pipelinesascode.tekton.dev/max-keep-runs: "2"
spec:
params:
- name: trigger_comment
value: |- # make sure to use |- or it will fail with a simple |
value: |
{{ trigger_comment }}
- name: repo_owner
value: "{{ repo_owner }}"
Expand Down
2 changes: 1 addition & 1 deletion pipeline-prow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: prow-commands
annotations:
pipelinesascode.tekton.dev/on-comment: |
^/(help|rebase|merge|lgtm|(assign|unassign|label|unlabel)[ ].*)$
^/(help|rebase|merge|lgtm|(cherry-pick|assign|unassign|label|unlabel)[ ].*)$
pipelinesascode.tekton.dev/max-keep-runs: "5"
spec:
params:
Expand Down
64 changes: 0 additions & 64 deletions pipelines_as_code_prow/base.yaml

This file was deleted.

29 changes: 29 additions & 0 deletions pipelines_as_code_prow/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,32 @@
Please resolve any issues and try again.
"""

# Add new error message template for cherry-pick
CHERRY_PICK_ERROR = """
### ❌ Cherry Pick Failed
Failed to cherry-pick changes from PR #{source_pr} to branch `{target_branch}`:
* Status Code: `{status_code}`
* Error: `{error_text}`
**Possible causes:**
* Merge conflicts
* Branch protection rules
* Invalid branch name
* Missing permissions
Please resolve any issues and try again.
"""

CHERRY_PICK_SUCCESS = """
### ✅ Cherry Pick Successful
Successfully cherry-picked changes from PR #{source_pr} to branch `{target_branch}`.
**Details:**
* Source PR: #{source_pr}
* Target Branch: `{target_branch}`
* Cherry-picked by: @{user}
* New commit SHA: `{commit_sha}`
"""
Loading

0 comments on commit 2523df5

Please sign in to comment.