Repository navigation
Expand ciq-cherry-pick with alternate source parameters #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PlaidCat
wants to merge
15
commits into
mainline
Choose a base branch
from
{rnicolescu}_commit_source
base: mainline
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1eaa02e
ciq_tag.py: Move it to kt/ktlib
roxanan1996 1365634
kt/ktlib: Add new commit header class
roxanan1996 f47e1b7
ciq-cherry-pick.py use commitHeader instead
roxanan1996 2845988
check_kernel_commits.py: Use CommitHeader
roxanan1996 22c4bf4
run_interdiff.py: Use CommitHeader
roxanan1996 99ed9ac
jira_pr_check.py: Use CommitHeader instead
roxanan1996 cec76cb
kt/ktlib/commit_source.py: Add extra commit source tags
roxanan1996 5881fea
ciq-cherry-pick: add pick-fixes
roxanan1996 0f901b9
tests: Cover CherryPickCommand, CommitHeader and git_remote; fix expo…
PlaidCat aa777e6
ciq-cherry-pick: accept --sha as deprecated alias for --commit
PlaidCat 99fb399
git_remote: fetch_for_commit_source resolves branch-style commit sources
PlaidCat fe433eb
upstream_sources.yaml: fix centos-stream-10 url, use https for kernel…
PlaidCat 0c3e04a
ciq-cherry-pick: accept --ticket as deprecated alias for --jira
PlaidCat 58e5909
ammend: ciq-cherry-pick.py use commitHeader instead
PlaidCat db3356b
ammend: kt/ktlib/commit_source.py: Add extra commit source tags
PlaidCat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import inspect | ||
| import re | ||
| from dataclasses import asdict, dataclass | ||
| from typing import Optional | ||
|
|
||
| from kt.ktlib.ciq_tag import CiqMsg | ||
|
|
||
|
|
||
| @dataclass | ||
| class CommitHeader: | ||
| """ | ||
| Name-field view of the CIQ tag block in a commit message. | ||
| At the moment it represents only commits for cve fixes. | ||
| """ | ||
|
|
||
| jira: Optional[str] = None | ||
| # TODO maybe have a union of these cve_bf, cve_pre and cve) idk | ||
| cve: Optional[str] = None | ||
| cve_bf: Optional[str] = None | ||
| cve_pre: Optional[str] = None | ||
| commit_author: Optional[str] = None | ||
| commit: Optional[str] = None | ||
| commit_source: Optional[str] = None | ||
| commit_source_sha: Optional[str] = None | ||
| commit_source_author: Optional[str] = None | ||
| upstream_diff: Optional[str] = None | ||
|
|
||
| # There are a pile of other tags that have not been codified consistently keep them rather than silently | ||
| # dropping them. Provides the option of using them in the future if needed. | ||
| extras: Optional[dict] = None | ||
|
|
||
| def __post_init__(self): | ||
| # Every value of every tag as parsed: not a dataclass field. Ignored by asdict()/to_str(). | ||
| # populated by from_ciq_msg() | ||
| self._raw_tags: dict = {} | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, env): | ||
| params = inspect.signature(cls).parameters | ||
| known = {k: v for k, v in env.items() if k in params and k != "extras"} | ||
| # CVE numbers are matched case-insensitively upstream and always stored | ||
| # upper-cased (CVE-\d{4}-\d+); tag values with extra prose are kept as-is. | ||
| for key in ("cve", "cve_bf", "cve_pre"): | ||
| value = known.get(key) | ||
| if value and re.fullmatch(r"(?i)cve-\d{4}-\d+", value.strip()): | ||
| known[key] = value.strip().upper() | ||
| extras = {k: v for k, v in env.items() if k not in params and v is not None} | ||
| header = cls(**known) | ||
| if extras: | ||
| header.extras = extras | ||
| return header | ||
|
|
||
| @classmethod | ||
| def from_ciq_msg(cls, ciq_msg: CiqMsg) -> CommitHeader: | ||
| # CiqMsg has multible values for tags and their values. The scalar | ||
| # fields keep the first value; every occurrence is collected in | ||
| # _raw_tags so callers (jiras(), upstream_commits()) can see them all. | ||
| msg_dict = {} | ||
| raw: dict = {} | ||
| for tag, value in ciq_msg._tags_dict.items(): | ||
| # TODO a bug here around upstream-diff from CiqMsg, this is an workaround | ||
| if type(tag.value) is tuple: | ||
| name = tag.value[0][0] | ||
| else: | ||
| name = tag.value[0] | ||
|
|
||
| tag_name = name.replace("-", "_") | ||
| for v in value: # Collect all tags. | ||
| raw.setdefault(tag_name, []).append(v[1]._value) | ||
| msg_dict[tag_name] = raw[tag_name][0] # use the first value for the tag | ||
|
|
||
| header = cls.from_dict(msg_dict) | ||
| header._raw_tags = raw | ||
|
|
||
| return header | ||
|
|
||
| @classmethod | ||
| def from_commit_body(cls, commit_body: str) -> CommitHeader: | ||
| if commit_body and not commit_body.endswith("\n"): | ||
| commit_body += "\n" | ||
| ciq_msg = CiqMsg(commit_body) | ||
| return cls.from_ciq_msg(ciq_msg=ciq_msg) | ||
|
Comment on lines
+83
to
+84
|
||
|
|
||
| def to_str(self) -> str: | ||
| lines = [] | ||
| for key, value in asdict(self).items(): | ||
| if key == "extras" or not value: | ||
| continue | ||
| if key == "jira" and "," in value: | ||
| lines += [f"jira {t.strip()}" for t in value.split(",") if t.strip()] | ||
| else: | ||
| lines.append(f"{key.replace('_', '-')} {value}") | ||
|
|
||
| if self.extras: | ||
| lines += [f"{k.replace('_', '-')} {v}" for k, v in self.extras.items()] | ||
|
|
||
| return "\n".join(lines) | ||
|
|
||
| def jiras(self) -> list: | ||
| # Return a list of individual jira tickets. Handles both repeated | ||
| # `jira <ticket>` lines and comma-separated values on one line. | ||
| tickets = [] | ||
| for value in self._raw_tags.get("jira", [self.jira]): | ||
| if not value: | ||
| continue | ||
| tickets += [t.strip() for t in value.split(",") if t.strip()] | ||
| return tickets | ||
|
|
||
| def upstream_commits(self) -> list: | ||
| # Return a list of upstream commits in a message, there should NOT be more than one but in the event there is | ||
| # return them all | ||
| if self._raw_tags and "commit" in self._raw_tags: | ||
| return [c for c in self._raw_tags["commit"] if c and c != "-"] | ||
| return [self.commit] if (self.commit and self.commit != "-") else [] | ||
|
|
||
| def is_cve(self) -> bool: | ||
| return self.cve or self.cve_bf or self.cve_pre | ||
|
|
||
| # A commit header may have multiple cve tags. But we are interested if it has the cve tag, since that | ||
| # is the commit it represents | ||
| # If not cve tag, check cve-bf or cve-pre | ||
| # we may have situations where a commit has (cve, cve-pre) or (cve, cve-bf) because a deps may be a cve itself, because we do not enforce this, but our current tooling uses only tag | ||
| def cve_number(self) -> str: | ||
| if self.cve: | ||
| return self.cve | ||
|
|
||
| if self.cve_bf: | ||
| return self.cve_bf | ||
|
|
||
| if self.cve_pre: | ||
| return self.cve_pre | ||
|
|
||
| def set_cve(self, cve_number): | ||
| # Make sure only one cve tag is used | ||
| # Our current tooling uses only 1 tag at the moment, but this may change and result in a commit that has 2 cve tags (cve, cve-bf) or (cve, cve-pre) for commits that are deps but cve as well | ||
| original_tags = ", ".join( | ||
| f"{t} {v}" for t, v in (("cve", self.cve), ("cve-bf", self.cve_bf), ("cve-pre", self.cve_pre)) if v | ||
| ) | ||
| self.cve_bf = None | ||
| self.cve_pre = None | ||
| self.cve = cve_number | ||
| print(f"CVE {cve_number} for hash {self.commit} and original tags {original_tags}") | ||
|
|
||
| def make_it_cve_bf(self): | ||
| # Interchange cve with cve-bf | ||
| if not self.is_cve(): | ||
| return | ||
|
|
||
| # It already has a cve_bf val, it's fine | ||
| if self.cve_bf: | ||
| return | ||
|
|
||
| self.cve_bf = self.cve | ||
| self.cve = None | ||
|
|
||
| def all_cves(self) -> list: | ||
| """Return a list of cve numbers. | ||
|
|
||
| A tag value may list several CVEs comma-separated (cve CVE-1, CVE-2); | ||
| split those into individual numbers. | ||
| """ | ||
|
|
||
| cves = [] | ||
| for value in (self.cve, self.cve_bf, self.cve_pre): | ||
| if not value: | ||
| continue | ||
| cves += [c.strip() for c in value.split(",") if c.strip()] | ||
|
Comment on lines
+166
to
+169
|
||
|
|
||
| return cves | ||
|
|
||
| def extract_upstream_name_and_sha(self): | ||
| """Return a pair of (commit_source, commit_source_sha) if source is not mainline | ||
| Otherwise returns (None, commit) if the source is mainline | ||
| """ | ||
|
|
||
| if self.commit_source_sha: | ||
| return (self.commit_source, self.commit_source_sha) | ||
|
|
||
| if self.commit and self.commit != "-": | ||
| return (None, self.commit) | ||
|
|
||
| return (None, None) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.