-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicenseupdate.py
More file actions
103 lines (79 loc) · 3.26 KB
/
licenseupdate.py
File metadata and controls
103 lines (79 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3.5
# -*-coding:utf-8 -*
import argparse
import getpass
import xml.etree.ElementTree as ET
import sh
from service import jira_service
from service import github_service
"""
Update files license headers in all Lutece components on Github
"""
JIRA_URL = "https://dev.lutece.paris.fr/jira/"
GITHUB_PLATFORM = ["lutece-platform", "lutece_secteur-public"]
def main():
parser = argparse.ArgumentParser(
description=('Script permettant de mettre à jour les licences sur '
+ 'tous les composants Lutece dans GitHub')
)
parser.add_argument(
"jira_user",
help="Votre code d'accès sur Jira"
)
parser.add_argument(
"github_user",
help="Votre code d'accès sur GitHub"
)
args = parser.parse_args()
jira_user = args.jira_user
github_user = args.github_user
jira_password = getpass.getpass(prompt="Mot de passe Jira : ")
jira_client = jira_service.JiraService(JIRA_URL, jira_user, jira_password)
github_password = getpass.getpass(prompt="Mot de passe GitHub : ")
github_client = github_service.GithubService(github_user, github_password)
for lutece_organization in LUTECE_ORGANIZATIONS
org = github_client.get_organization(lutece_organization)
for repo in org.get_repos():
update_license(github_repo, jira_client, project_key, github_user,
github_password)
def update_license(github_repo, jira_client, git_user, git_password):
"""Update license"""
url = github_repo.clone_url
name = github_repo.name
sh.git.clone(url, name)
sh.cd(name)
sh.git.checkout("develop")
sh.mvn("license:format")
if (sh.git.status("--porcelain") != ""):
sh.git.add("src/java")
sh.git.add("src/test/java")
try:
issue_key = ""
tree = ET.parse('pom.xml')
project = tree.getroot()
ns = {"mvn": "http://maven.apache.org/POM/4.0.0"}
properties = project.find("mvn:properties", ns)
if properties is not None:
jira_project_name = properties.find('mvn:jiraProjectName', ns)
if jira_project_name is not None:
project_key = jira_project_name.text
version = jira_client.get_last_version(project_key)
user = jira_client.user
issue_key = jira_client.create_issue(project_key,
"Update license",
user, "Major", "Task",
version)
except FileNotFoundError, ET.ParseError:
pass
issue_key += " : " if issue_key else ""
sh.git.commit("-m", "{}Update license".format(issue_key))
remote = str(sh.git.remote("get-url", "--push", "origin").replace("\n",
""))
remote = remote.replace("https://",
"https://{}:{}@".format(git_user, git_password))
sh.git.push(remote, "develop")
jira_client.close_issue(issue_key)
sh.cd("..")
sh.rm("-rf", name)
if __name__ == "__main__":
main()