Skip to content

Commit 8bc95e3

Browse files
authored
feature: add --author parameter (#369)
* feat: add --author parameter to PR body * refactor: move author to agent init * build: bump project version
1 parent 3994557 commit 8bc95e3

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

osa_tool/config/settings/arguments.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ settings:
129129
advanced — run all enabled features based on provided flags.
130130
choices: [ "basic", "auto", "advanced" ]
131131

132+
author:
133+
aliases: [ "--author" ]
134+
type: str
135+
description: |
136+
Primarily used for web interface. When set, the tool will add Author to the Pull Request body.
137+
132138
web_mode:
133139
aliases: [ "--web-mode" ]
134140
type: flag

osa_tool/git_agent/git_agent.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from git import GitCommandError, InvalidGitRepositoryError, Repo
1010

1111
from osa_tool.analytics.metadata import (
12-
RepositoryMetadata,
1312
GitHubMetadataLoader,
1413
GitLabMetadataLoader,
1514
GitverseMetadataLoader,
15+
RepositoryMetadata,
1616
)
1717
from osa_tool.utils.logger import logger
1818
from osa_tool.utils.utils import get_base_repo_url, parse_folder_name
@@ -25,7 +25,8 @@ class GitAgent(abc.ABC):
2525
commit and push changes, and create pull requests.
2626
2727
Attributes:
28-
AGENT_SIGNATURE: A signature string appended to pull request descriptions.
28+
agent_signature: A signature string appended to a pull request descriptions.
29+
author: An author name that appended to a pull request description.
2930
repo_url: The URL of the Git repository.
3031
clone_dir: The directory where the repository will be cloned.
3132
branch_name: The name of the branch to be created.
@@ -37,20 +38,17 @@ class GitAgent(abc.ABC):
3738
pr_report_body: A formatted message for a pull request.
3839
"""
3940

40-
AGENT_SIGNATURE = (
41-
"\n\n---\n*This PR was created by [osa_tool](https://github.com/aimclub/OSA).*"
42-
"\n_OSA just makes your open source project better!_"
43-
)
44-
45-
def __init__(self, repo_url: str, repo_branch_name: str = None, branch_name: str = "osa_tool"):
41+
def __init__(self, repo_url: str, repo_branch_name: str = None, branch_name: str = "osa_tool", author: str = None):
4642
"""Initializes the agent with repository info.
4743
4844
Args:
4945
repo_url: The URL of the GitHub repository.
5046
repo_branch_name: The name of the repository's branch to be checked out.
5147
branch_name: The name of the branch to be created. Defaults to "osa_tool".
48+
author: The name of the author of the pull request.
5249
"""
5350
load_dotenv()
51+
self.author = author
5452
self.repo_url = repo_url
5553
self.clone_dir = os.path.join(os.getcwd(), parse_folder_name(repo_url))
5654
self.branch_name = branch_name
@@ -61,6 +59,17 @@ def __init__(self, repo_url: str, repo_branch_name: str = None, branch_name: str
6159
self.base_branch = repo_branch_name or self.metadata.default_branch
6260
self.pr_report_body = ""
6361

62+
@property
63+
def agent_signature(self) -> str:
64+
signature = "\n\n---"
65+
if self.author:
66+
signature += f"\n*Author: {self.author}.*"
67+
signature += (
68+
"\n*This PR was created by [osa_tool](https://github.com/aimclub/OSA).*"
69+
"\n_OSA just makes your open source project better!_"
70+
)
71+
return signature
72+
6473
@abc.abstractmethod
6574
def _get_token(self) -> str:
6675
"""Return platform-specific token from environment."""
@@ -438,7 +447,7 @@ def create_pull_request(self, title: str = None, body: str = None) -> None:
438447
pr_title = title if title else last_commit.message
439448
pr_body = body if body else last_commit.message
440449
pr_body += self.pr_report_body
441-
pr_body += self.AGENT_SIGNATURE
450+
pr_body += self.agent_signature
442451
pr_data = {
443452
"title": pr_title,
444453
"head": head_branch,
@@ -648,7 +657,7 @@ def create_pull_request(self, title: str = None, body: str = None) -> None:
648657
mr_title = title if title else last_commit.message
649658
mr_body = body if body else last_commit.message
650659
mr_body += self.pr_report_body
651-
mr_body += self.AGENT_SIGNATURE
660+
mr_body += self.agent_signature
652661

653662
mr_data = {
654663
"title": mr_title,
@@ -838,7 +847,7 @@ def create_pull_request(self, title: str = None, body: str = None) -> None:
838847
pr_title = title if title else last_commit.message
839848
pr_body = body if body else last_commit.message
840849
pr_body += self.pr_report_body
841-
pr_body += self.AGENT_SIGNATURE
850+
pr_body += self.agent_signature
842851

843852
pr_data = {
844853
"title": pr_title,

osa_tool/run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from pydantic import ValidationError
1111

1212
from osa_tool.aboutgen.about_generator import AboutGenerator
13-
from osa_tool.analytics.report_maker import ReportGenerator, WhatHasBeenDoneReportGenerator
13+
from osa_tool.analytics.report_maker import (
14+
ReportGenerator,
15+
WhatHasBeenDoneReportGenerator,
16+
)
1417
from osa_tool.analytics.sourcerank import SourceRank
1518
from osa_tool.config.settings import ConfigLoader, GitSettings
1619
from osa_tool.conversion.notebook_converter import NotebookConverter
@@ -249,13 +252,13 @@ def main():
249252

250253
def initialize_git_platform(args):
251254
if "github.com" in args.repository:
252-
git_agent = GitHubAgent(args.repository, args.branch)
255+
git_agent = GitHubAgent(args.repository, args.branch, author=args.author)
253256
workflow_manager = GitHubWorkflowManager(args.repository, git_agent.metadata, args)
254257
elif "gitlab." in args.repository:
255-
git_agent = GitLabAgent(args.repository, args.branch)
258+
git_agent = GitLabAgent(args.repository, args.branch, author=args.author)
256259
workflow_manager = GitLabWorkflowManager(args.repository, git_agent.metadata, args)
257260
elif "gitverse.ru" in args.repository:
258-
git_agent = GitverseAgent(args.repository, args.branch)
261+
git_agent = GitverseAgent(args.repository, args.branch, author=args.author)
259262
workflow_manager = GitverseWorkflowManager(args.repository, git_agent.metadata, args)
260263
else:
261264
raise ValueError(f"Cannot initialize Git Agent and Workflow Manager for this platform: {args.repository}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "osa_tool"
3-
version = "0.2.5.1"
3+
version = "0.2.6"
44
description = "Tool that just makes your open source project better!"
55
requires-python = ">=3.10,<4.0"
66
authors = [

0 commit comments

Comments
 (0)