gerrit_to_platform package¶
Submodules¶
gerrit_to_platform.change_merged module¶
Handler for change-merged events.
- gerrit_to_platform.change_merged.change_merged(change: str, change_url: str, change_owner: str, change_owner_username: str, project: str, branch: str, topic: str, submitter: str, submitter_username: str, commit: str, newrev: str)[source]¶
Handle change-merged hook.
- Parameters:
change (str) – change ID
change_url (str) – change URL
change_owner (str) – change owner eg: ‘Foo <foo@example.com>’
change_owner_username (str) – change owner username eg: ‘foo’
project (str) – Gerrit project name
branch (str) – branch change is against
topic (str) – topic change is part of
submitter (str) – submitter of change eg: ‘Foo <foo@example.com>’
submitter_username (str) – submitter of change username eg: ‘foo’
commit (str) – SHA1 of commit
newrev (str) – SHA1 of commit
gerrit_to_platform.comment_added module¶
Handler for comment-added events.
- gerrit_to_platform.comment_added.check_cooldown(change_number: str, workflow_name: str) bool[source]¶
Check if workflow trigger is within cooldown period.
- Parameters:
change_number – Gerrit change number
workflow_name – Name of the workflow to trigger
- Returns:
True if trigger is allowed, False if still in cooldown
- Return type:
- gerrit_to_platform.comment_added.comment_added(context: Context, change: str, change_url: str, change_owner: str, change_owner_username: str, project: str, branch: str, topic: str, author: str, author_username: str, commit: str, comment: str)[source]¶
Handle comment-added hook.
Supports two trigger mechanisms: 1. gha-<action> <workflow_name> pattern for direct workflow triggering
Example: “gha-run csit-2n-perftest nic=intel-e810cq drv=avf” The full command line is passed to the workflow via GERRIT_COMMENT input for parameter parsing by the GitHub Actions workflow.
Keyword mapping from config file (legacy behavior)
Approval scores should be added as –<approval category id> <score>
When a score is removed it should be –<approval category id>-oldValue <score>
Multiple scores and old scores may be passed
ex: –Code-Review +1 –Code-Review-oldValue 0
- Parameters:
context (typer.Context) – handler for the typer context to allow for extra non-defined parameters (code scores, see above)
change (str) – change ID
change_url (str) – change URL
change_owner (str) – change owner eg: ‘Foo <foo@example.com>’
change_owner_username (str) – change owner username eg: ‘foo’
project (str) – Gerrit project name
branch (str) – branch change is against
topic (str) – topic change is part of
submitter (str) – submitter of change eg: ‘Foo <foo@example.com>’
submitter_username (str) – submitter of change username eg: ‘foo’
commit (str) – SHA1 of commit
comment (str) – the comment added to the change
gerrit_to_platform.config module¶
Configuration subsystem.
- class gerrit_to_platform.config.Platform(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
EnumEnumeration of all platforms recognized by the app.
- GITHUB = 'github'¶
- GITLAB = 'gitlab'¶
- class gerrit_to_platform.config.ReplicationRemotes[source]¶
Bases:
TypedDictPlatform Dictionary definition.
- gerrit_to_platform.config.get_config(config_type: str = 'config') ConfigParser[source]¶
Get the config object.
- Parameters:
config_type (str) – Type of configuration file that the parser should use
- Returns:
- A loaded ConfigParser object with the requested
configuration file
- Return type:
ConfigParser
Notes
replication.configfollows git’s config-file syntax, which permits the same option key to repeat inside a section (the canonical example is multiplefetch = ...refspecs under one[remote "..."]). Python’sconfigparserraisesDuplicateOptionErrorfor that pattern unlessstrictis false, so we disable the strict check here.g2ponly readsurl,authgroupandremotenamestylefrom the remote sections, never the multi-valuedfetchkey, so the “last value wins” semantics thatstrict=Falseintroduces for duplicates have no functional impact. The same parser is used forgerrit_to_platform.inifor consistency; that file is operator-controlled and does not contain duplicate keys in practice.
- gerrit_to_platform.config.get_mapping(mapping_section: str) Dict[str, str] | None[source]¶
Return all of the keyword to job mappings
- gerrit_to_platform.config.get_replication_remotes() ReplicationRemotes[source]¶
Get the replication remotes available.
- Returns:
- All the replication remotes defined the Gerrit
configuration file
- Return type:
gerrit_to_platform.github module¶
Github connection module.
- gerrit_to_platform.github.dispatch_workflow(owner: str, repository: str, workflow_id: str, ref: str, inputs: Dict[str, str]) Any[source]¶
Trigger target workflow on GitHub.
- gerrit_to_platform.github.filter_path(search_filter: str, workflow: Dict[str, str]) bool[source]¶
Case insensitive path filter for use in lambda filters.
- gerrit_to_platform.github.filter_workflows(owner: str, repository: str, search_filter: str, search_required: bool = False) List[Dict[str, str]][source]¶
Return a case insensitive filtered list of workflows.
All workflows must meet the basic filtering of containing the search_filter in the name as well as “gerrit” in the name.
If search_required is true, then the list will contiain all workflows that contain “required” in the name
If search_required is false (the default), then the list will _exclude_ all workflows that contain “required” in the name.
- Parameters:
owner (str) – GitHub owner (entity or organization)
repository (str) – target repository
search_filter (str) – the substring to search for in workflow filenames
search_required (bool) – if workflows with “required” in the filename are to be returned. If false, then required workflows will be filtered out, if true only required workflows will be returned.
- Returns:
- list of dictionaries containing all workflows
that meet the search criteria of having “gerrit” in the name, the search_filter substring, and either required or not required according to the search_required argument.
- Return type:
gerrit_to_platform.helpers module¶
Common helper functions.
- gerrit_to_platform.helpers.choose_dispatch(platform: Platform) Callable | None[source]¶
Choose platform job dispatcher.
- Parameters:
platform (Platform) – the platform that the dispatch is being looked up for
- Returns:
- The appropriate callable matching the dispatch_worfklow call
signature for the platform
- None: If no dispatch_workflow is defined for the platform passed in a
None is returned
- Return type:
Callable
- gerrit_to_platform.helpers.choose_filter_workflows(platform: Platform) Callable | None[source]¶
Choose platform workflow filter.
- Parameters:
platform (Platform) – the platform that the filter_workflows is being looked up for
- Returns:
- The appropriate callable matching the filter_workflows call
signature for the platform
- None: If no filter_workflows is defined for the platform passed in a
None is returned
- Return type:
Callable
- gerrit_to_platform.helpers.convert_repo_name(remotes: ReplicationRemotes, platform: Platform, remote: str, repository: str) str[source]¶
Convert the repository name based on the remotenamestyle of the target platform/owner.
- Parameters:
remotes (ReplicationRemotes) – object containing the defined remotes styles
platform (Platform) – what platform is the conversion happening against
remote (str) – The specific remote that is being worked on
repository (str) – The repository name that needs conversion
- Returns:
- The repository name converted to the appropriate flattening for
the target remote
- Return type:
- gerrit_to_platform.helpers.find_and_dispatch(project: str, workflow_filter: str, inputs: Dict[str, str]) int[source]¶
Find relevant workflows and dispatch them.
- gerrit_to_platform.helpers.get_change_id(change: str) str[source]¶
Return a Gerrit change identifier from the hook
--changevalue.Gerrit hooks pass
--changein one of two shapes depending on the server version and configuration:Legacy triplet (e.g.
project~branch~Iabc123def...). The third tilde-separated field is the commit-messageChange-Idfooter. When this shape is detected the function returns thatI...value, preserving the previous behaviour.Modern compact (Gerrit 3.x and later, e.g.
ccsdk%2Fapps~1— URL-encoded project followed by the change number). Gerrit no longer ships the commit-messageChange-Idfooter in the hook argv for this shape, so the function returns the compact id as-is. It is still a unique, stable identifier per change and works as aGERRIT_CHANGE_IDworkflow input (e.g. for concurrency keys).
- Parameters:
change (str) – the
--changevalue supplied by the Gerrit hook plugin.- Returns:
The legacy
I...Change-Id when present, otherwise the modern compactproject~numberidentifier verbatim.- Return type:
- Raises:
ValueError – if
changematches neither shape. The previous implementation raisedIndexErrorhere, which made triage harder for operators inspecting hook tracebacks.
- gerrit_to_platform.helpers.get_change_number(change_url: str) str[source]¶
Get the Gerrit change_number
- gerrit_to_platform.helpers.get_change_refspec(change_number: str, patchset: str) str[source]¶
Return the change refspec from the change number (str) and patch number
gerrit_to_platform.patchset_created module¶
Handler for patchset-created events.
- gerrit_to_platform.patchset_created.patchset_created(change: str, kind: str, change_url: str, change_owner: str, change_owner_username: str, project: str, branch: str, topic: str, uploader: str, uploader_username: str, commit: str, patchset: str)[source]¶
Handle patcheset-created hook.
- Parameters:
change (str) – change ID
kind (str) – type of change
change_url (str) – change URL
change_owner (str) – change owner eg: ‘Foo <foo@example.com>’
change_owner_username (str) – change owner username eg: ‘foo’
project (str) – Gerrit project name
branch (str) – branch change is against
topic (str) – topic change is part of
uploader (str) – uploader of change eg: ‘Foo <foo@example.com>’
uploader_username (str) – uploader of change username eg: ‘foo’
commit (str) – SHA1 of commit
patchset (str) – patchset number