fetch-issues.py 6.77 KB
Newer Older
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python3


from collections import namedtuple
import os.path
import csv
import io
import json
import requests
10
import time
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
11
12
13
14
15

USER_HOME = os.path.expanduser("~")
SECRETS_FILE = os.path.join(USER_HOME, "fetch-issues.json")


16
17
18



Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
19
def get_secret(key):
20
21
22
#    with open(SECRETS_FILE) as f:
#        return json.load(f)[key]
    return os.getenv(key)
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
23

24
25
26
27
28
29
def get_github_header():
    oauth_token = get_secret("oauth_token")
    if (oauth_token == None):
        return {'Accept': 'application/vnd.github.full+json'}
    else:
        return {'Accept': 'application/vnd.github.full+json','Authorization': 'token '+oauth_token}
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
30
31
32
33
34

Issue = namedtuple("Issue", ["created", "title", "url"])


def github_parser(json_string, ticket_base_url):
35
    return (
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
36
37
38
39
40
41
        Issue(
            created=issue["created_at"].split("T")[0],
            title=issue["title"],
            url="/".join([ticket_base_url, str(issue["number"])]),
        )
        for issue in json.loads(json_string)
42
    )
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
43
44
45


def redmine_parser(json_string, ticket_base_url):
46
    return (
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
47
48
49
50
51
52
        Issue(
            created=issue["start_date"],
            title=issue["subject"],
            url="/".join([ticket_base_url, str(issue["id"])]),
        )
        for issue in json.loads(json_string)["issues"]
53
    )
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
54
55
56


def trac_parser(csv_string, ticket_base_url):
57
    return (
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
58
59
60
61
62
63
        Issue(
            created=issue["time"].split(" ")[0],
            title=issue["summary"],
            url="/".join([ticket_base_url, issue["\ufeffid"]]),
        )
        for issue in csv.DictReader(io.StringIO(csv_string))
64
    )
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
65
66
67


def mantis_parser(csv_string, ticket_base_url):
68
    return (
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
69
70
71
72
73
74
        Issue(
            created=issue["Date Submitted"],
            title=issue["Summary"],
            url="{}{}".format(ticket_base_url, issue["Id"]),
        )
        for issue in csv.DictReader(io.StringIO(csv_string))
75
    )
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
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


IssueTracker = namedtuple(
    "IssueTracker",
    ["parser", "project", "url", "headers", "ticket_base_url"],
)


issue_trackers = [
    IssueTracker(
        parser=trac_parser,
        project="OpenModelica",
        url="https://trac.openmodelica.org/OpenModelica/query?status=accepted&status=assigned&status=new&status=reopened&summary=~into-cps&or&status=accepted&status=assigned&status=new&status=reopened&description=~into-cps&format=csv&col=id&col=summary&col=time&order=priority",  # noqa
        headers=None,
        ticket_base_url="https://trac.openmodelica.org/OpenModelica/ticket",
    ),
    IssueTracker(
        parser=redmine_parser,
        project="Modelio",
        url="http://forge.modelio.org/projects/intocps/issues.json",
        headers=None,
        ticket_base_url="http://forge.modelio.org/issues",
    ),
    IssueTracker(
        parser=github_parser,
        project="INTO-CPS Application",
        url="https://api.github.com/repos/into-cps/INTO-CPS_Application/issues?state=open",  # noqa
103
        headers=get_github_header(),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
104
105
106
107
108
109
        ticket_base_url="https://github.com/into-cps/INTO-CPS_Application/issues",  # noqa
    ),
    IssueTracker(
        parser=github_parser,
        project="Overture",
        url="https://api.github.com/repos/overturetool/overture/issues?state=open&labels=into-cps",  # noqa
110
        headers=get_github_header(),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
111
112
113
114
115
116
        ticket_base_url="https://github.com/overturetool/overture/issues",
    ),
    IssueTracker(
        parser=github_parser,
        project="Overture-FMU",
        url="https://api.github.com/repos/overturetool/overture-fmu/issues?state=open",  # noqa
117
        headers=get_github_header(),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
118
119
120
121
122
123
        ticket_base_url="https://github.com/overturetool/overture-fmu/issues",  # noqa
    ),
    IssueTracker(
        parser=github_parser,
        project="20-sim FMU Export",
        url="https://api.github.com/repos/controllab/fmi-export-20sim/issues?state=open",  # noqa
124
        headers=get_github_header(),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
125
126
127
128
129
130
131
        ticket_base_url="https://github.com/controllab/fmi-export-20sim/issues",  # noqa
    ),

    IssueTracker(
        parser=github_parser,
        project="INTO-CPS DSE",
        url="https://api.github.com/repos/CarlGamble/INTO-CPS-DSE/issues?state=open",  # noqa
132
        headers=get_github_header(),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
133
134
        ticket_base_url="https://github.com/CarlGamble/INTO-CPS-DSE/issues",
    ),
135
136
137
138
    IssueTracker(
        parser=github_parser,
        project="INTO-CPS UI",
        url="https://api.github.com/repos/into-cps/intocps-ui/issues?state=open",  # noqa
139
        headers=get_github_header(),
140
141
        ticket_base_url="https://github.com/into-cps/intocps-ui/issues",
    ),
142
143
144
145
146
147
148
#    IssueTracker(
#        parser=mantis_parser,
#        project="RT-Tester",
#        url="https://software.verified.de/mantis/csv_export.php",
#        headers=get_secret("rtt_headers"),
#        ticket_base_url="https://software.verified.de/mantis/view.php?id=",
#    ),
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
149
150
151
152
]


def main():
153
    
154
    timestr = time.strftime("%Y-W%W")#"%Y-%m-%d")
155
    print (timestr)
156
157
158
159
160
161
162
163
164
165
    week = time.strftime("%W")
    year = time.strftime("%Y")
    name = '{}-W{}'.format(year,week)
    fileName = name+'.md'
    
    fc = open('fetch-out','w')
    fc.write(fileName)
    fc.close()
    
    f = open(fileName,'w')
166
167
    f.write('---\n')
    f.write('layout: default\n')
168
    f.write('title: Week {} {}, Weekly Issues Digest\n'.format(week,year))
169
170
    f.write('---\n\n')

171
    f.write('# Week {} {}, Weekly Issues Digest for INTO-CPS\n\n'.format(week,year))
172
173
174

    f.write('## Currently Open Issues\n\n')
    
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
175
    for tracker in sorted(issue_trackers, key=lambda tracker: tracker.project):
176
        print("### {}".format(tracker.project))
177
        f.write("\n### {}\n\n".format(tracker.project))
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
178
179
180
181
        for issue in tracker.parser(
            requests.get(tracker.url, headers=tracker.headers).text,
            tracker.ticket_base_url,
        ):
182
            line = "* [{} - ({})]({})".format(
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
183
                    issue.title,
184
                    issue.created,
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
185
186
                    issue.url,
                )
187
188
            f.write(line+'\n')
            print(line)
189
    f.write("\n\n# History of Weekly Digests\n\n")
190
    f.write("Below you will find a list of weekly digests giving a historical overview of all known issues across all the tools that are part of INTO-CPS.\n")
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
191

192
193
194
195
196
    if not os.access('issue-history.txt', os.R_OK):
        with open('issue-history.txt','w+') as fc:
            fc.close()

    with open('issue-history.txt',) as fc:
197
198
199
200
        my_lines = fc.readlines()
        fc.close()

        for s in my_lines:
201
202
            l = s.replace('\n', '').replace('\r', '')
            f.write("* [{}]({}.html)".format(l,l))
203
204
205
206
207
208
209
210
211
212
213
214
215

        
        if any(name in s for s in my_lines):
            print("already there\n")
        else:
            lines = [name]+ my_lines
       
            with open('issue-history.txt','w') as fh:
                fh.writelines(["%s\n" % item  for item in lines])
                fh.close()
        
    f.close()
                
Anders Franz Terkelsen's avatar
Anders Franz Terkelsen committed
216
217
if __name__ == "__main__":
    main()