ProjectPythia / .github

Community health files: Contributing guidelines, Code of Conduct, ...
Apache License 2.0
2 stars 4 forks source link

Harmonize GitHub issue labels across all repos in the organization? #44

Closed brian-rose closed 1 year ago

brian-rose commented 1 year ago

Currently we have to manually create labels such as "High priority" at the repo level, and the badges all end up with different colors.

It would be really useful to harmonize this across repos, especially now that we're using the project board to track work across all repos. Is this easy to do?

brian-rose commented 1 year ago

I will investigate whether this is simple or not.

brian-rose commented 1 year ago

I manually created new default tags at the organization level following these instructions

I don't think these will automatically propagate down to existing repos though. Probably just affects newly created repos.

brian-rose commented 1 year ago

I also went through several of our high traffic repos and manually edited the colors of the most important labels:

I pulled these colors from https://github.com/ProjectPythia/.github/blob/main/.github/labels.yml where we have a bunch of standard labels defined. But I don't really understand how GitHub interprets this file and whether it's possible to programatically change labels across repos.

brian-rose commented 1 year ago

The harmonization of the colors helps make our project board easier to read, I think.

We could do more of this manual syncing of colors across all repos but it's pretty tedious work.

clyne commented 1 year ago

Nice! Having the appropriate defaults in place for new repos probably addresses the most urgent part of this issue; we could think of dropping the priority for the harmonizing of the existing repos.

brian-rose commented 1 year ago

Makes sense! I will do that.

dopplershift commented 1 year ago

Looks like I have a script to us the API to do this:

#!/usr/bin/env python
# Copyright (c) 2016 Unidata.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

import github

def get_token():
    r"""
    Get the API token to use for talking to GitHub
    """
    try:
        with open('token', 'rt') as token_file:
            return token_file.readline()[:-1]
    except IOError:
        import os
        return os.environ['GITHUB_TOKEN']

if __name__ == '__main__':
    import argparse

    # Get command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('repository', help='Repository', type=str)
    parser.add_argument('-o', '--org', help='Organization', type=str, default='Unidata')
    parser.add_argument('action', help='Action to take', type=str, choices=['get', 'update'],
                        default='get', nargs='?')
    parser.add_argument('-f', '--filename', help='File for storing labels', type=str,
                        default='labels.txt')
    args = parser.parse_args()

    # Get the github API entry
    token = get_token()
    g = github.Github(token)

    # Get the organization
    org = g.get_organization(args.org)

    # Get the object for this repository
    repo = org.get_repo(args.repository)

    #
    if args.action == 'get':
        print('Getting labels from {0}'.format(args.repository))
        with open(args.filename, 'wt') as outfile:
            labels = sorted((l.name, l.color) for l in repo.get_labels())
            outfile.write(''.join('{0}|{1}\n'.format(*l) for l in labels))
    elif args.action == 'update':
        if token is None:
            raise RuntimeError('Updating labels requires a personal access token!')
        print('Updating labels on {0}'.format(args.repository))
        with open(args.filename, 'rt') as infile:
            for line in infile:
                parts = line.strip().split('|')
                if len(parts) == 3:
                    old_name, new_name, color = parts
                else:
                    new_name, color = parts
                    old_name = new_name

                try:
                    label = repo.get_label(old_name)
                    label.edit(new_name, color)
                    print('Updated label: {0.name}->{1} (#{2})'.format(label, new_name, color))
                except github.GithubException:
                    label = repo.create_label(new_name, color)
                    print('Created label: {0.name} (#{0.color})'.format(label))
brian-rose commented 1 year ago

Looks like I've been trying to reinvent a wheel here.

We actually have this workflow already: https://github.com/ProjectPythia/.github/blob/main/.github/workflows/labels.yml

which is running hourly and syncing labels from the file https://github.com/ProjectPythia/.github/blob/main/.github/labels.yml to an explicit list of repos.

Seems that the only problem is the list of repos is way out of date. I will open a PR to get it updated.

brian-rose commented 1 year ago

This is the tool we already use to sync labels: https://github.com/micnncim/action-label-syncer

brian-rose commented 1 year ago

In https://github.com/ProjectPythia/.github/issues/24 we gave ourselves another 90 days with a valid PAT to keep the syncing script working.

https://github.com/ProjectPythia/.github/pull/46 shows that we can sync labels just by adding a repo name to the list.

Now just need to extend that list to all remaining repos in our org.