• 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/create_migration_issue.py
1
#!/usr/bin/env python
2
#  -*- coding: utf-8 -*-
3
# License AGPLv3 (https://www.gnu.org/licenses/agpl-3.0-standalone.html)
4
"""
5
This script creates a migration issue for a new Odoo version
6
in all repositories. This issue lists all known addons in the previous version.
7

8
Installation
9
============
10

11
For using this utility, you need to install these dependencies:
12

13
* github3.py library for handling Github calls. To install it, use:
14
  `sudo pip install github3.py`.
15

16
Configuration
17
=============
18

19
You must have a file called oca.cfg on the same folder of the script for
20
storing credentials parameters. You can generate an skeleton config running
21
this script for a first time.
22

23
Usage
24
=====
25
oca-create-migration-issues [-h] [-p PROJECTS [PROJECTS ...]] [-e EMAIL]
26
                            [-t TARGET_ORG]
27
                            source target
28

29
positional arguments:
30
  source                Source branch (existing)
31
  target                Target branch (to create)
32

33
optional arguments:
34
  -h, --help            show this help message and exit
35
  -p PROJECTS [PROJECTS ...], --projects PROJECTS [PROJECTS ...]
36
                        List of specific projects to migrate
37
  -e EMAIL, --email EMAIL
38
                        Provides an email address used to commit on GitHub if
39
                        the one associated to the GitHub account is not public
40
  -t TARGET_ORG, --target-org TARGET_ORG
41
                        By default, the GitHub organization used is OCA. This
42
                        arg lets you provide an alternative organization
43

44
This script will perform the following operations for each project:
45

46
* Create a milestone (if it does not exist) for new version.
47
* Create an issue enumerating the modules to migrate, with the milestone
48
  assigned, and with the labels "help wanted" and "work in progress" (if
49
  exist).
50

51
Known issues / Roadmap
52
======================
53

54
* Issue enumerating the module list contains a list to a Wiki page that should
55
  be formatted this way:
56
  https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-{branch}
57

58
Credits
59
=======
60

61
Contributors
62
------------
63

64
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
65
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
66

67
Maintainer
68
----------
69

70
.. image:: https://odoo-community.org/logo.png
71
   :alt: Odoo Community Association
72
   :target: https://odoo-community.org
73

74
This module is maintained by the OCA.
75

76
OCA, or the Odoo Community Association, is a nonprofit organization whose
77
mission is to support the collaborative development of Odoo features and
78
promote its widespread use.
79

80
To contribute to this module, please visit http://odoo-community.org.
81
"""
82

83
from __future__ import print_function
×
84

85
import argparse
×
86

87
import github3
×
88

89
from . import github_login, oca_projects
×
90
from .config import read_config
×
91

92
MANIFESTS = ("__openerp__.py", "__manifest__.py")
×
93

94

95
class MigrationIssuesCreator(object):
×
96
    def __init__(self, source, target, target_org=None, email=None):
×
97
        # Read config
98
        config = read_config()
×
99
        self.gh_token = config.get("GitHub", "token")
×
100
        # Connect to GitHub
101
        self.github = github_login.login()
×
102
        gh_user = self.github.me()
×
103
        if not gh_user.email and not email:
×
104
            raise Exception(
×
105
                "Email required to commit to github. Please provide one on "
106
                "the command line or make the one of your github profile "
107
                "public."
108
            )
109
        self.gh_credentials = {
×
110
            "name": gh_user.name or str(gh_user),
111
            "email": gh_user.email or email,
112
        }
113
        self.gh_source_branch = source
×
114
        self.gh_target_branch = target
×
115
        self.gh_org = target_org or "OCA"
×
116

117
    def _get_modules_list(self, repo, root_contents):
×
118
        """Get the list of the modules in previous branch."""
119
        modules = []
×
120
        for root_content in root_contents.values():
×
121
            if root_content.type != "dir":
×
122
                continue
×
123
            module_contents = repo.directory_contents(
×
124
                root_content.path, self.gh_source_branch, return_as=dict
125
            ).keys()
126
            if any(x in module_contents for x in MANIFESTS):
×
127
                modules.append(root_content.path)
×
128
        return modules
×
129

130
    def _create_branch_milestone(self, repo):
×
131
        for milestone in repo.milestones():
×
132
            if milestone.title == self.gh_target_branch:
×
133
                print(" milestone already exists")
×
134
                return milestone
×
135
        return repo.create_milestone(self.gh_target_branch)
×
136

137
    def _create_migration_issue(self, repo, modules, milestone):
×
138
        title = "Migration to version %s" % self.gh_target_branch
×
139
        # Check first if it already exists
140
        for issue in repo.issues(milestone=milestone.number):
×
141
            if issue.title == title:
×
142
                print(" migration issue already exists")
×
143
                return issue
×
144
        body = (
×
145
            "# Todo\n\nhttps://github.com/OCA/maintainer-tools/wiki/"
146
            "Migration-to-version-%s\n\n# Modules to migrate\n\n"
147
            % self.gh_target_branch
148
        )
149
        body += "\n".join(["- [ ] %s" % x for x in modules])
×
150
        body += (
×
151
            "\n\nMissing module? Check https://github.com/OCA/maintainer-"
152
            "tools/wiki/%5BFAQ%5D-Missing-modules-in-migration-issue-list"
153
        )
154
        # Make sure labels exists
155
        labels = []
×
156
        for label in repo.labels():
×
157
            if label.name in ["help wanted", "work in progress", "no stale"]:
×
158
                labels.append(label.name)
×
159
        return repo.create_issue(
×
160
            title=title, body=body, milestone=milestone.number, labels=labels
161
        )
162

163
    def _migrate_project(self, project):
×
164
        print("Preparing project %s/%s" % (self.gh_org, project))
×
165
        repo = self.github.repository(self.gh_org, project)
×
166
        try:
×
167
            root_contents = repo.directory_contents(
×
168
                "",
169
                self.gh_source_branch,
170
                return_as=dict,
171
            )
172
        except github3.exceptions.NotFoundError:
×
173
            print(
×
174
                " no commit found on branch {}, skipping".format(self.gh_source_branch)
175
            )
176
            return
×
177
        modules = self._get_modules_list(repo, root_contents)
×
178
        milestone = self._create_branch_milestone(repo)
×
179
        self._create_migration_issue(repo, sorted(modules), milestone)
×
180

181
    def do_migration(self, projects=None):
×
182
        if not projects:
×
183
            projects = oca_projects.get_repositories()
×
184
        for project in sorted(projects):
×
185
            self._migrate_project(project)
×
186

187

188
def get_parser():
×
189
    parser = argparse.ArgumentParser(
×
190
        description="Migrate one OCA branch from one version to another, "
191
        "applying the needed transformations",
192
        add_help=True,
193
    )
194
    parser.add_argument("source", help="Source branch (existing)")
×
195
    parser.add_argument("target", help="Target branch (to create)")
×
196
    parser.add_argument(
×
197
        "-p",
198
        "--projects",
199
        dest="projects",
200
        nargs="+",
201
        default=[],
202
        help="List of specific projects to migrate",
203
    )
204
    parser.add_argument(
×
205
        "-e",
206
        "--email",
207
        dest="email",
208
        help=(
209
            "Provides an email address used to commit on GitHub if the one "
210
            "associated to the GitHub account is not public"
211
        ),
212
    )
213
    parser.add_argument(
×
214
        "-t",
215
        "--target-org",
216
        dest="target_org",
217
        help=(
218
            "By default, the GitHub organization used is OCA. This arg lets "
219
            "you provide an alternative organization"
220
        ),
221
    )
222
    return parser
×
223

224

225
def main():
×
226
    args = get_parser().parse_args()
×
227
    migrator = MigrationIssuesCreator(
×
228
        source=args.source,
229
        target=args.target,
230
        target_org=args.target_org,
231
        email=args.email,
232
    )
233
    migrator.do_migration(projects=args.projects)
×
234

235

236
if __name__ == "__main__":
×
237
    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