[ADD] pull request show list of all repo from an organization
This commit is contained in:
parent
9b466e552d
commit
187dc83bb4
3 changed files with 112 additions and 0 deletions
|
|
@ -120,3 +120,9 @@ Check if contains "auto_install" in manifest, change to False.
|
|||
source ./.venv/bin/activate
|
||||
python odoo/odoo-bin scaffold MODULE_NAME addons/REPO_NAME/
|
||||
```
|
||||
|
||||
# Pull request
|
||||
## Show all pull request from organization
|
||||
```bash
|
||||
/script/pull_request_ERPLibre.py --github_token ### --organization ERPLibre
|
||||
```
|
||||
|
|
|
|||
|
|
@ -774,6 +774,30 @@ class GitTool:
|
|||
upstream_remote.fetch)()
|
||||
print('Remote "%s" fetched' % repo_info.organization)
|
||||
|
||||
def get_pull_request_repo(self, upstream_url: str, github_token: str,
|
||||
organization_name: str = ""):
|
||||
"""
|
||||
|
||||
:param upstream_url:
|
||||
:param github_token:
|
||||
:param organization_name:
|
||||
:return: List of url if success, else False
|
||||
"""
|
||||
gh = GitHub(token=github_token)
|
||||
parsed_url = parse(upstream_url)
|
||||
|
||||
# Fork the repo
|
||||
status, user = gh.user.get()
|
||||
user_name = user['login'] if not organization_name else organization_name
|
||||
status, lst_pull = gh.repos[user_name][parsed_url.repo].pulls.get()
|
||||
if type(lst_pull) is dict:
|
||||
print(f"For url {upstream_url}, got {lst_pull.get('message')}")
|
||||
return False
|
||||
else:
|
||||
for pull in lst_pull:
|
||||
print(pull.get("html_url"))
|
||||
return lst_pull
|
||||
|
||||
def fork_repo(self, upstream_url: str, github_token: str,
|
||||
organization_name: str = ""):
|
||||
# https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-scopes-for-oauth-apps/
|
||||
|
|
|
|||
82
script/pull_request_ERPLibre.py
Executable file
82
script/pull_request_ERPLibre.py
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
#!./.venv/bin/python
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
new_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
sys.path.append(new_path)
|
||||
|
||||
from script.git_tool import GitTool
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
CST_EL_GITHUB_TOKEN = "EL_GITHUB_TOKEN"
|
||||
|
||||
|
||||
def get_config():
|
||||
"""Parse command line arguments, extracting the config file name,
|
||||
returning the union of config file and command line arguments
|
||||
|
||||
:return: dict of config file settings and command line arguments
|
||||
"""
|
||||
config = GitTool.get_project_config()
|
||||
|
||||
# TODO update description
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description='''\
|
||||
''',
|
||||
epilog='''\
|
||||
'''
|
||||
)
|
||||
parser.add_argument('-d', '--dir', dest="dir", default="./",
|
||||
help="Path of repo to change remote, including submodule.")
|
||||
parser.add_argument('--organization', dest="organization", default="ERPLibre",
|
||||
help="Choose organization to fork and change all repo.")
|
||||
parser.add_argument('--github_token', dest="github_token",
|
||||
default=config.get(CST_EL_GITHUB_TOKEN),
|
||||
help="GitHub token generated by user")
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
config = get_config()
|
||||
github_token = config.github_token
|
||||
git_tool = GitTool()
|
||||
|
||||
if not github_token:
|
||||
raise ValueError("Missing github_token")
|
||||
|
||||
organization_name = config.organization
|
||||
lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir, add_repo_root=True)
|
||||
lst_repo_organization = [git_tool.get_transformed_repo_info_from_url(
|
||||
a.get("url"), repo_path=config.dir, organization_force=organization_name,
|
||||
is_submodule=a.get("is_submodule"), sub_path=a.get("sub_path"),
|
||||
revision=a.get("revision"), clone_depth=a.get("clone_depth"))
|
||||
for a in lst_repo]
|
||||
|
||||
url_not_found_count = 0
|
||||
url_found_count = 0
|
||||
|
||||
i = 0
|
||||
total = len(lst_repo_organization)
|
||||
for repo in lst_repo_organization:
|
||||
i += 1
|
||||
print(f"Nb element {i}/{total} - {repo.project_name}")
|
||||
url = repo.url
|
||||
|
||||
status = git_tool.get_pull_request_repo(upstream_url=url,
|
||||
github_token=github_token,
|
||||
organization_name=organization_name)
|
||||
if status is False:
|
||||
url_not_found_count += 1
|
||||
else:
|
||||
url_found_count += len(status)
|
||||
|
||||
print(f"Repository not found: {url_not_found_count}")
|
||||
print(f"URL found: {url_found_count}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in a new issue