Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PR Pre Checks

on:
pull_request:
push:
branches:
- mainline

jobs:
pre-commit-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Create Python Venv
run: |
python -m venv venv
source venv/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH

- name: Install Python deps
run: |
python -m pip install -e ".[dev]"
python -m pip list

- name: Lint
run: |
pre-commit install
pre-commit run --all-files --show-diff-on-failure --verbose --color=always
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__pycache__/

# Ruff stuff:
.ruff_cache/

venv/
env/
.venv/
.env/

*.egg-info/
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.0
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
182 changes: 108 additions & 74 deletions check_kernel_commits.py

Large diffs are not rendered by default.

41 changes: 23 additions & 18 deletions ciq-cherry-pick.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
import argparse
import os
import subprocess

import git
from ciq_helpers import CIQ_cherry_pick_commit_standardization
from ciq_helpers import CIQ_original_commit_author_to_tag_string

from ciq_helpers import CIQ_cherry_pick_commit_standardization, CIQ_original_commit_author_to_tag_string

# from ciq_helpers import *

MERGE_MSG = git.Repo(os.getcwd()).git_dir + '/MERGE_MSG'
MERGE_MSG = git.Repo(os.getcwd()).git_dir + "/MERGE_MSG"

if __name__ == '__main__':
if __name__ == "__main__":
print("CIQ custom cherry picker")
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--sha', help='Target SHA1 to cherry-pick')
parser.add_argument('--ticket', help='Ticket associated to cherry-pick work, comma separated list is supported.')
parser.add_argument('--ciq-tag', help="Tags for commit message <feature><-optional modifier> <identifier>.\n"
"example: cve CVE-2022-45884 - A patch for a CVE Fix.\n"
" cve-bf CVE-1974-0001 - A bug fix for a CVE currently being patched\n"
" cve-pre CVE-1974-0001 - A pre-condition or dependency needed for the CVE\n"
"Multiple tags are separated with a comma. ex: cve CVE-1974-0001, cve CVE-1974-0002\n")
parser.add_argument("--sha", help="Target SHA1 to cherry-pick")
parser.add_argument("--ticket", help="Ticket associated to cherry-pick work, comma separated list is supported.")
parser.add_argument(
"--ciq-tag",
help="Tags for commit message <feature><-optional modifier> <identifier>.\n"
"example: cve CVE-2022-45884 - A patch for a CVE Fix.\n"
" cve-bf CVE-1974-0001 - A bug fix for a CVE currently being patched\n"
" cve-pre CVE-1974-0001 - A pre-condition or dependency needed for the CVE\n"
"Multiple tags are separated with a comma. ex: cve CVE-1974-0001, cve CVE-1974-0002\n",
)
args = parser.parse_args()

# Expand the provided SHA1 to the full SHA1 in case it's either abbreviated or an expression
git_sha_res = subprocess.run(['git', 'show', '--pretty=%H', '-s', args.sha], stdout=subprocess.PIPE)
git_sha_res = subprocess.run(["git", "show", "--pretty=%H", "-s", args.sha], stdout=subprocess.PIPE)
if git_sha_res.returncode != 0:
print(f"[FAILED] git show --pretty=%H -s {args.sha}")
print("Subprocess Call:")
print(git_sha_res)
print("")
else:
args.sha = git_sha_res.stdout.decode('utf-8').strip()
args.sha = git_sha_res.stdout.decode("utf-8").strip()

tags = []
if args.ciq_tag is not None:
tags = args.ciq_tag.split(',')
tags = args.ciq_tag.split(",")

author = CIQ_original_commit_author_to_tag_string(repo_path=os.getcwd(), sha=args.sha)
if author is None:
exit(1)

git_res = subprocess.run(['git', 'cherry-pick', '-nsx', args.sha])
git_res = subprocess.run(["git", "cherry-pick", "-nsx", args.sha])
if git_res.returncode != 0:
print(f"[FAILED] git cherry-pick -nsx {args.sha}")
print(" Manually resolve conflict and include `upstream-diff` tag in commit message")
Expand All @@ -47,7 +52,7 @@
print("")

print(os.getcwd())
subprocess.run(['cp', MERGE_MSG, f'{MERGE_MSG}.bak'])
subprocess.run(["cp", MERGE_MSG, f"{MERGE_MSG}.bak"])

tags.append(author)

Expand All @@ -58,11 +63,11 @@

print(f"Cherry Pick New Message for {args.sha}")
for line in new_msg:
print(line.strip('\n'))
print(line.strip("\n"))
print(f"\n Original Message located here: {MERGE_MSG}.bak")

with open(MERGE_MSG, "w") as file:
file.writelines(new_msg)

if git_res.returncode == 0:
subprocess.run(['git', 'commit', '-F', MERGE_MSG])
subprocess.run(["git", "commit", "-F", MERGE_MSG])
21 changes: 11 additions & 10 deletions ciq_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

# CIQ Kernel Tools function library

import git
import os
import re
import subprocess

import git


def process_full_commit_message(commit):
"""Process the full git commit message specific to the CIQ Kernel Tools.
Expand Down Expand Up @@ -84,9 +85,7 @@ def get_backport_commit_data(repo, branch, common_ancestor, allow_duplicates=Fal

for line in lines:
if len(commit) > 0 and line.startswith(b"commit "):
upstream_commit, cves, tickets, upstream_subject, repo_commit = (
process_full_commit_message(commit)
)
upstream_commit, cves, tickets, upstream_subject, repo_commit = process_full_commit_message(commit)
if upstream_commit in upstream_commits:
print(f"WARNING: {upstream_commit} already in upstream_commits")
if not allow_duplicates:
Expand All @@ -104,9 +103,7 @@ def get_backport_commit_data(repo, branch, common_ancestor, allow_duplicates=Fal
return upstream_commits, True


def CIQ_cherry_pick_commit_standardization(
lines, commit, tags=None, jira="", optional_msg=""
):
def CIQ_cherry_pick_commit_standardization(lines, commit, tags=None, jira="", optional_msg=""):
"""Standardize CIQ the cherry-pick commit message.
Parameters:
lines: Original SHAS commit message.
Expand Down Expand Up @@ -159,13 +156,17 @@ def CIQ_original_commit_author_to_tag_string(repo_path, sha):

Return: String for Tag
"""
git_auth_res = subprocess.run(['git', 'show', '--pretty="%aN <%aE>"', '--no-patch', sha], stderr=subprocess.PIPE,
stdout=subprocess.PIPE, cwd=repo_path)
git_auth_res = subprocess.run(
["git", "show", '--pretty="%aN <%aE>"', "--no-patch", sha],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=repo_path,
)
if git_auth_res.returncode != 0:
print(f"[FAILED] git show --pretty='%aN <%aE>' --no-patch {sha}")
print(f"[FAILED][STDERR:{git_auth_res.returncode}] {git_auth_res.stderr.decode('utf-8')}")
return None
return "commit-author " + git_auth_res.stdout.decode('utf-8').replace('\"', '').strip()
return "commit-author " + git_auth_res.stdout.decode("utf-8").replace('"', "").strip()


def repo_init(repo):
Expand Down
Loading