• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OCA / maintainer-tools / 13228537945

09 Feb 2025 06:34PM UTC coverage: 35.131%. Remained the same
13228537945

Pull #644

github

web-flow
Merge 8b3aeb3fa into 16f1fc1f8
Pull Request #644: Ignore archived projects

437 of 1188 branches covered (36.78%)

645 of 1836 relevant lines covered (35.13%)

3.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tools/set_repo_labels.py
1
# -*- coding: utf-8 -*-
2
# License AGPLv3 (https://www.gnu.org/licenses/agpl-3.0-standalone.html)
3
"""
4
Create and modify labels on github to have same labels and same color
5
on all repo
6
"""
7

8
from __future__ import print_function
×
9

10
import click
×
11

12
from .github_login import login
×
13

14
REPO_TO_IGNORE = [
×
15
    ".github",
16
    "mirrors-flake8",
17
]
18

19
# List of labels to sync on all repositories
20
# {name: (color, description)}
21
ALL_LABELS = {
×
22
    "bug": ("fc2929", None),
23
    "duplicate": ("cccccc", None),
24
    "enhancement": ("84b6eb", None),
25
    "help wanted": ("159818", None),
26
    "invalid": ("e6e6e6", None),
27
    "question": ("cc317c", None),
28
    "needs fixing": ("eb6420", None),
29
    "needs review": ("fbca04", None),
30
    "needs more information": ("eb6420", None),
31
    "approved": ("045509", None),
32
    "work in progress": ("0052cc", None),
33
    "wontfix": ("ffffff", None),
34
    "migration": ("d4c5f9", None),
35
    "ready to merge": ("bfdadc", None),
36
    # Labels related to actions/stale github workflow
37
    "no stale": (
38
        "524D44",
39
        "Use this label to prevent the automated stale action "
40
        "from closing this PR/Issue.",
41
    ),
42
    "stale": (
43
        "006B75",
44
        "PR/Issue without recent activity, it'll be soon closed automatically.",
45
    ),
46
}
47

48

49
@click.command()
×
50
@click.option("--org", default="OCA")
×
51
@click.option("--repos", required=False)
×
52
def main(
×
53
    org: str,
54
    repos: str,
55
) -> None:
56
    gh = login()
×
57
    repos = repos.split(",") if repos else []
×
58
    if repos:
×
59
        for repo_name in repos:
×
60
            repo = gh.repository(org, repo_name)
×
61
            _update_labels(repo)
×
62
    else:
63
        for repo in gh.repositories_by(org):
×
64
            if repo.name in REPO_TO_IGNORE:
×
65
                continue
×
66
            _update_labels(repo)
×
67

68

69
def _update_labels(repo):
×
70
    repo_labels = {label.name.lower(): label for label in repo.labels()}
×
71
    target_labels = set(ALL_LABELS.keys())
×
72
    existing_labels = set(repo_labels.keys())
×
73
    labels_to_update = target_labels & existing_labels
×
74
    labels_to_create = target_labels - existing_labels
×
75
    # Report if extra labels are found, nothing to do though
76
    extra_labels = existing_labels - target_labels
×
77
    for label_name in extra_labels:
×
78
        print(f"Found extra label '{repo_labels[label_name].name}' in {repo.name}")
×
79
    # Check existing labels
80
    for label_name in labels_to_update:
×
81
        label_color, label_description = ALL_LABELS[label_name]
×
82
        repo_label = repo_labels[label_name]
×
83
        if (
×
84
            repo_label.name != label_name
85
            or repo_label.color != label_color
86
            or (
87
                label_description is not None
88
                and repo_label.description != label_description
89
            )
90
        ):
91
            print(
×
92
                f"Updating label '{repo_label.name}' -> '{label_name}', "
93
                f"'{repo_label.color}' -> '{label_color}', "
94
                f"'{repo_label.description}' -> '{label_description}' "
95
                f"in {repo.name}"
96
            )
97
            repo_label.update(label_name, label_color, label_description)
×
98
    # Create labels
99
    for label_name in labels_to_create:
×
100
        label_color, label_description = ALL_LABELS[label_name]
×
101
        print(f"Creating label '{label_name}' in {repo.name}")
×
102
        repo.create_label(label_name, label_color, label_description)
×
103

104

105
if __name__ == "__main__":
×
106
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc