diff --git a/hacking/pr_labeler/data/docs_team_info.md b/hacking/pr_labeler/data/docs_team_info.md new file mode 100644 index 0000000000..8d8c0d7fb9 --- /dev/null +++ b/hacking/pr_labeler/data/docs_team_info.md @@ -0,0 +1,2 @@ +Thanks for your Ansible docs contribution! We talk about Ansible documentation on matrix at [#docs:ansible.im](https://matrix.to/#/#docs:ansible.im) and on libera IRC at #ansible-docs if you ever want to join us and chat about the docs! We meet there on Tuesdays (see [the Ansible calendar](https://github.com/ansible/community/blob/main/meetings/README.md)) and welcome additions to our [weekly agenda items](https://github.com/ansible/community/issues/678) - scroll down to find the upcoming agenda and add a comment to put something new on that agenda. + diff --git a/hacking/pr_labeler/label.py b/hacking/pr_labeler/label.py index a92b561c6a..55e76badc0 100644 --- a/hacking/pr_labeler/label.py +++ b/hacking/pr_labeler/label.py @@ -83,6 +83,22 @@ def get_previously_labeled(ctx: IssueOrPrCtx) -> frozenset[str]: return frozenset(previously_labeled) +def create_comment(ctx: IssueOrPrCtx, body: str) -> None: + if ctx.dry_run: + return + if isinstance(ctx, IssueLabelerCtx): + ctx.issue.create_comment(body) + else: + ctx.pr.create_issue_comment(body) + + +def get_data_file(name: str) -> str: + """ + Get a data file + """ + return (HERE / "data" / name).read_text("utf-8") + + def handle_codeowner_labels(ctx: PRLabelerCtx) -> None: labels = LABELS_BY_CODEOWNER.copy() owners = CodeOwners(CODEOWNERS) @@ -109,6 +125,23 @@ def add_label_if_new(ctx: IssueOrPrCtx, labels: Collection[str] | str) -> None: ctx.member.add_to_labels(*labels) +def new_contributor_welcome(ctx: IssueOrPrCtx) -> None: + """ + Welcome a new contributor to the repo with a message and a label + """ + previously_labeled = get_previously_labeled(ctx) + # This contributor has already been welcomed! + if "new_contributor" in previously_labeled: + return + if ctx.member.raw_data["author_association"] not in { + "FIRST_TIMER", + "FIRST_TIME_CONTRIBUTOR", + }: + return + add_label_if_new(ctx, "new_contributor") + create_comment(ctx, get_data_file("docs_team_info.md")) + + APP = typer.Typer() @@ -130,6 +163,7 @@ def process_pr(pr_number: int, dry_run: bool = False) -> None: handle_codeowner_labels(ctx) add_label_if_new(ctx, "needs_triage") + new_contributor_welcome(ctx) @APP.command(name="issue") @@ -142,6 +176,7 @@ def process_issue(issue_number: int, dry_run: bool = False) -> None: ctx = IssueLabelerCtx(client=gclient, repo=repo, issue=issue, dry_run=dry_run) add_label_if_new(ctx, "needs_triage") + new_contributor_welcome(ctx) if __name__ == "__main__":