• 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/oca_projects.py
1
# -*- coding: utf-8 -*-
2
# License AGPLv3 (https://www.gnu.org/licenses/agpl-3.0-standalone.html)
3
"""
4
Data about OCA Projects, with a few helper functions.
5

6
OCA_REPOSITORY_NAMES: list of OCA repository names
7

8
"""
9

10
from __future__ import print_function
×
11

12
import os
×
13
import shutil
×
14
import subprocess
×
15
import tempfile
×
16
from contextlib import contextmanager
×
17

18
import appdirs
×
19

20
from .config import NOT_ADDONS, is_main_branch
×
21
from .github_login import login
×
22

23
ALL = ["OCA_REPOSITORY_NAMES", "url"]
×
24

25

26
def get_repositories():
×
27
    gh = login()
×
28
    all_repos = [
×
29
        repo.name
30
        for repo in gh.repositories_by("OCA")
31
        if repo.name not in NOT_ADDONS and not repo.archived
32
    ]
33
    return all_repos
×
34

35

36
def get_repositories_and_branches(repos=(), branches=(), branch_filter=is_main_branch):
×
37
    gh = login()
×
38
    for repo in gh.repositories_by("OCA"):
×
39
        if repos and repo.name not in repos:
×
40
            continue
×
41
        if repo.name in NOT_ADDONS:
×
42
            continue
×
43
        for branch in repo.branches():
×
44
            if branches and branch.name not in branches:
×
45
                continue
×
46
            if branch_filter and not branch_filter(branch.name):
×
47
                continue
×
48
            yield repo.name, branch.name
×
49

50

51
try:
×
52
    OCA_REPOSITORY_NAMES = get_repositories()
×
53
except Exception as exc:
×
54
    print(exc)
×
55
    OCA_REPOSITORY_NAMES = []
×
56

57
OCA_REPOSITORY_NAMES.sort()
×
58

59
_OCA_REPOSITORY_NAMES = set(OCA_REPOSITORY_NAMES)
×
60

61
_URL_MAPPINGS = {
×
62
    "git": "git@github.com:%s/%s.git",
63
    "ssh": "ssh://git@github.com/%s/%s.git",
64
    "https": "https://github.com/%s/%s.git",
65
}
66

67

68
def url(project_name, protocol="git", org_name="OCA"):
×
69
    """get the URL for an OCA project repository"""
70
    return _URL_MAPPINGS[protocol] % (org_name, project_name)
×
71

72

73
class BranchNotFoundError(RuntimeError):
×
74
    pass
×
75

76

77
@contextmanager
×
78
def temporary_clone(project_name, branch=None, protocol="git", org_name="OCA"):
×
79
    """context manager that clones a git branch and cd to it, with cache"""
80
    # init cache directory
81
    cache_dir = appdirs.user_cache_dir("oca-mqt")
×
82
    repo_cache_dir = os.path.join(
×
83
        cache_dir, "github.com", org_name.lower(), project_name.lower()
84
    )
85
    if not os.path.isdir(repo_cache_dir):
×
86
        os.makedirs(repo_cache_dir)
×
87
        subprocess.check_call(["git", "init", "--bare"], cwd=repo_cache_dir)
×
88
    repo_url = url(project_name, protocol, org_name)
×
89
    # fetch all branches into cache
90
    fetch_cmd = [
×
91
        "git",
92
        "fetch",
93
        "--quiet",
94
        "--force",
95
        repo_url,
96
        "refs/heads/*:refs/heads/*",
97
    ]
98
    subprocess.check_call(fetch_cmd, cwd=repo_cache_dir)
×
99
    if branch:
×
100
        # check if branch exist
101
        branches = subprocess.check_output(
×
102
            ["git", "branch"], universal_newlines=True, cwd=repo_cache_dir
103
        )
104
        branches = [b.strip() for b in branches.split()]
×
105
        if branch not in branches:
×
106
            raise BranchNotFoundError()
×
107
    # clone to temp dir, with --reference to cache
108
    tempdir = tempfile.mkdtemp()
×
109
    try:
×
110
        clone_cmd = [
×
111
            "git",
112
            "clone",
113
            "--quiet",
114
            "--reference",
115
            repo_cache_dir,
116
        ]
117
        if branch:
×
118
            clone_cmd += [
×
119
                "--branch",
120
                branch,
121
            ]
122
        clone_cmd += [
×
123
            "--",
124
            repo_url,
125
            tempdir,
126
        ]
127
        subprocess.check_call(clone_cmd)
×
128
        cwd = os.getcwd()
×
129
        os.chdir(tempdir)
×
130
        try:
×
131
            yield
×
132
        finally:
133
            os.chdir(cwd)
×
134
    finally:
135
        shutil.rmtree(tempdir)
×
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