-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease_notes_generator.py
119 lines (95 loc) · 4.05 KB
/
release_notes_generator.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import sys
import asana
from dotenv import load_dotenv
from mdutils.mdutils import MdUtils
def initialize_release_notes():
"""Sets filename and header
Returns:
mdutils: Markdown file to hold list of completed tasks
"""
release_notes = MdUtils(file_name='release-notes')
release_notes.new_header(level=1, title='Release notes draft')
release_notes.title = release_notes.title.replace('\n', '')
return release_notes
class ReleaseNotesGenerator:
def __init__(self):
pass
load_dotenv()
project_id = os.getenv('PROJECT_ID')
section_id = os.getenv('SECTION_ID')
tag_id = os.getenv('TAG_ID')
if 'ASANA_TOKEN' in os.environ:
client = asana.Client.access_token(os.environ['ASANA_TOKEN'])
try:
client.users.me()
print('authorized')
except asana.error.NoAuthorizationError as e:
print('could not authorize. please get or update ASANA_TOKEN')
sys.exit(1)
def get_tasks_with_tag(self):
"""Gets all tasks in the Done section with a particular tag
Returns:
list: A list of all tasks, incomplete or complete, with a matching tag_id
"""
tasks = self.client.tasks.get_tasks_for_section(self.section_id,
{'opt_fields': ['name', 'custom_fields', 'completed', 'tags']})
tasks_with_tag = []
for task in tasks:
tag_index = 0
for tag in task['tags']:
if tag['gid'] != self.tag_id:
while tag_index <= len(task['tags']):
tag_index += 1
continue
else:
tasks_with_tag.append(task)
if tasks_with_tag:
return tasks_with_tag
else:
print('No tasks were completed for v1.0.0')
sys.exit()
def write_tasks(self, task_type, tasks, release_notes):
"""Writes tasks with a matching task type to a Markdown file
Args:
task_type (string): The task type to search for
tasks (list): List of tasks to search through
release_notes (mdutils): Markdown file to write tasks to
Returns:
[mdutils]: Markdown file with task type headings and tasks
"""
heading_exists = False
for task in tasks:
if not task['completed']:
if task['custom_fields'][2]['display_value'] == task_type:
items = [
task['name'] + ' ' + '[[View ticket]]' + '(https://app.asana.com/0/' + self.project_id + '/' +
task['gid'] + ')']
if items is None:
print(' ')
elif items and (not heading_exists):
release_notes.new_header(level=2, title=task_type)
release_notes.new_list(items)
heading_exists = True
continue
elif items and heading_exists:
release_notes.new_list(items)
return release_notes
@staticmethod
def main():
"""Initializes, writes, and creates a Markdown file that contains a list of tasks with a 2.4 tag and task type
of New Content, Major Enhancement, Minor Enhancement, or Bug Fix
"""
release_notes_generator = ReleaseNotesGenerator()
release_notes = initialize_release_notes()
tasks = release_notes_generator.get_tasks_with_tag()
release_notes = release_notes_generator.write_tasks('Feature', tasks, release_notes)
release_notes = release_notes_generator.write_tasks('Bugfix', tasks, release_notes)
release_notes = release_notes_generator.write_tasks('Hotfix', tasks, release_notes)
release_notes = release_notes_generator.write_tasks('Testing', tasks, release_notes)
release_notes.create_md_file()
print('=====')
print('complete')
print('=====')
if __name__ == '__main__':
main()