From d7369ea4afca23a5f58d9b020d1b98b6216e57b5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 24 Mar 2021 17:51:38 -0500 Subject: [PATCH 1/2] add 'docsite_pr' label/facts to docs_info --- ansibullbot/triagers/ansible.py | 23 ++++++++++------- ansibullbot/triagers/plugins/docs_info.py | 30 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/ansibullbot/triagers/ansible.py b/ansibullbot/triagers/ansible.py index 1bdcb0d2c..6c689cf2b 100644 --- a/ansibullbot/triagers/ansible.py +++ b/ansibullbot/triagers/ansible.py @@ -1265,16 +1265,21 @@ def create_actions(self, iw, actions): if label_name in iw.labels: actions.unlabel.append(label_name) - # docs_only? - # https://github.com/ansible/ansibullbot/issues/1047 + # docs_only, docsite_pr? + # docs_only - https://github.com/ansible/ansibullbot/issues/1047 + # docsite_pr - https://github.com/ansible/ansibullbot/issues/1193 if iw.is_pullrequest(): - label_name = 'docs_only' - if self.meta['is_docs_only']: - if label_name not in iw.labels: - actions.newlabel.append(label_name) - else: - if label_name in iw.labels: - actions.unlabel.append(label_name) + label_meta = { + 'docs_only': 'is_docs_only', + 'docsite_pr': 'is_docsite_pr' + } + for label_name, meta_key in label_meta.items(): + if self.meta[meta_key]: + if label_name not in iw.labels: + actions.newlabel.append(label_name) + else: + if label_name in iw.labels: + actions.unlabel.append(label_name) if iw.is_pullrequest(): diff --git a/ansibullbot/triagers/plugins/docs_info.py b/ansibullbot/triagers/plugins/docs_info.py index 823585a7c..254da3017 100644 --- a/ansibullbot/triagers/plugins/docs_info.py +++ b/ansibullbot/triagers/plugins/docs_info.py @@ -14,6 +14,11 @@ "header": r"^\@+\s+(?P[\-]\d+),\d+\s(?P[\+]\d+),\d+", } +EDIT_ON_GITHUB_COMMITTER = { + "name": "GitHub", + "login": "web-flow", + } + @dataclasses.dataclass(eq=False, order=False) class ParsedFunc(): name: str @@ -276,10 +281,23 @@ def _is_docs_only(changed_file): return False +def _is_edited_on_github(commit): + """ Check if the committer information matches an instance of a change made + via 'Edit On GitHub'. + """ + + committer_info = { + "name": commit.commit.committer.name, + "login": commit.committer.login + } + + return committer_info == EDIT_ON_GITHUB_COMMITTER + def get_docs_facts(iw): """ Cycle through the files and gather facts about documentation changes. """ dfacts = { - "is_docs_only": False + "is_docs_only": False, + "is_docsite_pr": False } if not iw.is_pullrequest(): @@ -287,5 +305,13 @@ def get_docs_facts(iw): docs_only = False not in [_is_docs_only(f.raw_data) for f in iw.pr_files] - dfacts["is_docs_only"] = docs_only + edit_on_github = False + if docs_only: + edit_on_github = True in [_is_edited_on_github(commit) for commit in iw.commits] + + dfacts.update( + is_docs_only=docs_only, + is_docsite_pr=edit_on_github + ) + return dfacts From c491ff0b9231e68643482d69063224bafb3345f4 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 24 Mar 2021 17:58:21 -0500 Subject: [PATCH 2/2] add 'docsite_pr' test to docs_info unit tests --- tests/fixtures/docs_info/6_issue.yml | 23 +++++++++++++++++++ tests/unit/triagers/plugins/test_docs_info.py | 5 ++++ tests/utils/issue_mock.py | 23 +++++++++++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/docs_info/6_issue.yml diff --git a/tests/fixtures/docs_info/6_issue.yml b/tests/fixtures/docs_info/6_issue.yml new file mode 100644 index 000000000..8df3b4442 --- /dev/null +++ b/tests/fixtures/docs_info/6_issue.yml @@ -0,0 +1,23 @@ +html_url: https://github.com/ansible/ansible/pull/21313 +number: 21313 +github_repo: ansible +submitter: sommersoft +created_at: 2016-02-18T17:37:01Z +title: Test +body: | + test docs_info +events: + - event: committed + created_at: 2017-12-10T17:24:02Z + id: 1 + actor: + login: web-flow + name: GitHub + files: + - filename: docs/docsite/index.rst + status: modified + patch: | + @@ -2,2 +2,2 @@ + - index + + api + src_filepath: tests/fixtures/docs_info/files/docsite_index.rst \ No newline at end of file diff --git a/tests/unit/triagers/plugins/test_docs_info.py b/tests/unit/triagers/plugins/test_docs_info.py index 7a2ae066e..164adbd64 100644 --- a/tests/unit/triagers/plugins/test_docs_info.py +++ b/tests/unit/triagers/plugins/test_docs_info.py @@ -34,6 +34,11 @@ 'path': 'tests/fixtures/docs_info/3_issue.yml', 'expected_result': {'is_docs_only': False} }, + { + 'id': 'docsite_pr: Edited On GitHub', + 'path': 'tests/fixtures/docs_info/6_issue.yml', + 'expected_result': {'is_docsite_pr': True} + }, ) def datafile_id(datafile): diff --git a/tests/utils/issue_mock.py b/tests/utils/issue_mock.py index 28d99ccb1..cf91fd495 100644 --- a/tests/utils/issue_mock.py +++ b/tests/utils/issue_mock.py @@ -8,14 +8,28 @@ class ActorMock: class CommitterMock: - def __init__(self, date=None, login=None): + def __init__(self, date=None, login=None, name=None, email=None): self.date = date self.login = login + self.name = name + self.email = email class CommitBottomMock: - def __init__(self, committer_date=None, committer_login=None, message=""): - self.committer = CommitterMock(date=committer_date, login=committer_login) + def __init__( + self, + committer_date=None, + committer_login=None, + committer_name=None, + committer_email=None, + message="" + ): + self.committer = CommitterMock( + date=committer_date, + login=committer_login, + name=committer_name, + email=committer_email + ) self.message = message @@ -70,7 +84,8 @@ def commits(self): continue commit = CommitMock( committer_date=x['created_at'], - committer_login=x['actor']['login'] + committer_login=x['actor']['login'], + committer_name=x.get('actor', {}).get('name', '') ) for file in x.get('files', []): cfile = CommitFileMock(