Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Apply 'docsite_pr' Label #1537

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions ansibullbot/triagers/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down
30 changes: 28 additions & 2 deletions ansibullbot/triagers/plugins/docs_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"header": r"^\@+\s+(?P<del_start>[\-]\d+),\d+\s(?P<add_start>[\+]\d+),\d+",
}

EDIT_ON_GITHUB_COMMITTER = {
"name": "GitHub",
"login": "web-flow",
}

@dataclasses.dataclass(eq=False, order=False)
class ParsedFunc():
name: str
Expand Down Expand Up @@ -276,16 +281,37 @@ 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():
return dfacts

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
23 changes: 23 additions & 0 deletions tests/fixtures/docs_info/6_issue.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/unit/triagers/plugins/test_docs_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 19 additions & 4 deletions tests/utils/issue_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(
Expand Down