Example #1
0
    def on_pr_opened(self, api, payload):
        user = payload['pull_request']['user']['login']

        watchers = get_people_from_config(api, WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = defaultdict(list)

        for (watcher, watched_files) in watchers:
            watched_files = watched_files.split(' ')
            blacklisted_files = []

            for watched_file in watched_files:
                if watched_file.startswith('-'):
                    blacklisted_files.append(watched_file[1:])
            for blacklisted_file in blacklisted_files:
                watched_files.remove('-' + blacklisted_file)

            for filepath in api.get_changed_files():
                comment = False
                for watched_file in watched_files:
                    if fnmatch.fnmatch(filepath, watched_file):
                        comment = True
                        for blacklisted_file in blacklisted_files:
                            if (fnmatch.fnmatch(filepath, blacklisted_file)):
                                comment = False
                if (comment and user != watcher):
                    mentions[watcher].append(filepath)
        if not mentions:
            return

        message = build_message(mentions)
        api.post_comment(message)
Example #2
0
    def on_issue_labeled(self, api, payload):
        new_label = payload['label']['name']
        watchers = get_people_from_config(api, LABEL_WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = []
        creator = None
        sender = payload['sender']['login'].lower()

        if 'issue' in payload:
            creator = payload['issue']['user']['login'].lower()
        elif 'pull_request' in payload:
            creator = payload['pull_request']['user']['login'].lower()

        for (watcher, watched_labels) in watchers:
            if watcher == sender or watcher == creator:
                continue

            watched_labels = watched_labels.split(' ')

            if new_label in watched_labels:
                mentions.append(watcher)

        if not mentions:
            return

        message = build_label_message(mentions)
        api.post_comment(message)
Example #3
0
    def on_pr_opened(self, api, payload):
        user = payload["pull_request"]["user"]["login"]

        watchers = get_people_from_config(api, WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = defaultdict(list)
        for (watcher, watched_files) in watchers:
            watched_files = watched_files.split(" ")
            blacklisted_files = []
            for watched_file in watched_files:
                if watched_file.startswith("-"):
                    blacklisted_files.append(watched_file[1:])
            for blacklisted_file in blacklisted_files:
                watched_files.remove("-" + blacklisted_file)
            for filepath in api.get_changed_files():
                for blacklisted_file in blacklisted_files:
                    if filepath.startswith(blacklisted_file):
                        break
                else:
                    for watched_file in watched_files:
                        if filepath.startswith(watched_file) and user != watcher:
                            mentions[watcher].append(filepath)

        if not mentions:
            return

        message = build_message(mentions)
        api.post_comment(message)
Example #4
0
    def on_issue_labeled(self, api, payload):
        new_label = payload['label']['name']
        watchers = get_people_from_config(api, LABEL_WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = []
        creator = None
        sender = payload['sender']['login'].lower()

        if 'issue' in payload:
            creator = payload['issue']['user']['login'].lower()
        elif 'pull_request' in payload:
            creator = payload['pull_request']['user']['login'].lower()

        for (watcher, watched_labels) in watchers:
            if watcher == sender or watcher == creator:
                continue

            watched_labels = watched_labels.split(' ')

            if new_label in watched_labels:
                mentions.append(watcher)

        if not mentions:
            return

        message = build_label_message(mentions)
        api.post_comment(message)
Example #5
0
    def on_pr_opened(self, api, payload):
        user = payload['pull_request']['user']['login']
        diff = api.get_diff()
        changed_files = []
        for line in diff.split('\n'):
            if line.startswith('diff --git'):
                changed_files.extend(line.split('diff --git ')[-1].split(' '))

        # Remove the `a/` and `b/` parts of paths,
        # And get unique values using `set()`
        changed_files = set(
            map(lambda f: f if f.startswith('/') else f[2:], changed_files))

        watchers = get_people_from_config(api, WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = defaultdict(list)
        for (watcher, watched_files) in watchers:
            watched_files = watched_files.split(' ')
            blacklisted_files = []
            for watched_file in watched_files:
                if watched_file.startswith('-'):
                    blacklisted_files.append(watched_file[1:])
            for blacklisted_file in blacklisted_files:
                watched_files.remove('-' + blacklisted_file)
            for changed_file in changed_files:
                for blacklisted_file in blacklisted_files:
                    if changed_file.startswith(blacklisted_file):
                        break
                else:
                    for watched_file in watched_files:
                        if (changed_file.startswith(watched_file)
                                and user != watcher):
                            mentions[watcher].append(changed_file)

        if not mentions:
            return

        message = build_message(mentions)
        api.post_comment(message)
Example #6
0
    def on_pr_opened(self, api, payload):
        user = payload['pull_request']['user']['login']
        diff = api.get_diff()
        changed_files = []
        for line in diff.split('\n'):
            if line.startswith('diff --git'):
                changed_files.extend(line.split('diff --git ')[-1].split(' '))

        # Remove the `a/` and `b/` parts of paths,
        # And get unique values using `set()`
        changed_files = set(map(lambda f: f if f.startswith('/') else f[2:],
                                changed_files))

        watchers = get_people_from_config(api, WATCHERS_CONFIG_FILE)
        if not watchers:
            return

        mentions = defaultdict(list)
        for (watcher, watched_files) in watchers:
            watched_files = watched_files.split(' ')
            blacklisted_files = []
            for watched_file in watched_files:
                if watched_file.startswith('-'):
                    blacklisted_files.append(watched_file[1:])
            for blacklisted_file in blacklisted_files:
                watched_files.remove('-' + blacklisted_file)
            for changed_file in changed_files:
                for blacklisted_file in blacklisted_files:
                    if changed_file.startswith(blacklisted_file):
                        break
                else:
                    for watched_file in watched_files:
                        if (changed_file.startswith(watched_file) and
                                user != watcher):
                            mentions[watcher].append(changed_file)

        if not mentions:
            return

        message = build_message(mentions)
        api.post_comment(message)
Example #7
0
    def on_issue_labeled(self, api, payload):
        label_list = get_people_from_config(api, LABEL_WATCHERS_CONFIG_FILE)
        if not label_list:
            return

        new_label = payload['label']['name']
        existing_labels = []
        if 'issue' in payload:
            for label in payload['issue']['labels']:
                if new_label != label['name']:
                    existing_labels.append(label['name'])

        creator = None
        sender = payload['sender']['login'].lower()

        if 'issue' in payload:
            creator = payload['issue']['user']['login'].lower()
        elif 'pull_request' in payload:
            creator = payload['pull_request']['user']['login'].lower()

        label_map = dict()
        for watcher, watched_labels in label_list:      # reverse map
            if watcher == sender or watcher == creator:
                continue

            for label in watched_labels.split(' '):
                label_map.setdefault(label, set())
                label_map[label].add(watcher)

        mentions = deepcopy(label_map.get(new_label, set()))
        for label in existing_labels:
            for watcher in label_map.get(label, set()):
                if watcher in mentions:     # avoid cc'ing again
                    mentions.remove(watcher)

        if not mentions:
            return

        message = build_label_message(mentions)
        api.post_comment(message)