summaryrefslogtreecommitdiff
path: root/scripts/periupport_conv
blob: b8a21812a535a0b5837dbd043655b0d3bb1587fc (plain)
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
#! /bin/sh

[ $# -ne 2 ] && echo "$0 <ticket text output> <dest path>" && exit 0

SRC="$1"
DST="$2"
TICKET="$(basename $SRC .txt)"

[ ! -d "$DST" ] && mkdir -p "$DST"

# FIXME: ensure this is not already existing in another task
uuid_cmd="cat /proc/sys/kernel/random/uuid"

gawk -v dst="$DST" -v ticket="$TICKET" -v cmd="$uuid_cmd" '
	function make_filename(nam) {
			gsub(/[: /]+/, "_", nam)
			sub(/_$/, "", nam)
			return ticket "_" nam
		}
	/^B: /	{
			bsp_id = substr($0, 4, 40)
			desc = substr($0, 46)
			bsp_desc[bsp_id] = desc
			match(desc, /.*:/)
			task_key = substr(desc, RSTART, RLENGTH)
			gsub(/"/, "´", task_key)
			tasks[task_key][bsp_id] = bsp_id
		}

	/^U: /	{
			upstream_id = substr($0, 4, 40)
			upstream[bsp_id][upstream_id] = upstream_id
			upstream_desc[bsp_id][upstream_id] = substr($0, 46)
		}

	/^*: /		{ gsub(/"/, "´"); comment[bsp_id] = substr($0, 4) }

	/^Priority: N/	{ exit }

	END {
			for (task in tasks) {
				cmd | getline uuid; close(cmd);
				F = dst "/" make_filename(task) ".yaml"

				delete(sorted_idx)
				asorti(tasks[task], sorted_idx)

				print "title: \"From " ticket ", upport " task "\"" > F
				print "team: TBD" >> F
				print "key: " uuid >> F
				print "status: New" >> F
				print "assignee: TBD" >> F
				print "" >> F
				print "relationships:\n" >> F

				print "bsp-commits:" >> F
				for (idx in sorted_idx) {
					commit = tasks[task][sorted_idx[idx]]
					print "  - " commit " # " bsp_desc[commit] >> F
				}
				print "" >> F

				print "upstream:" >> F
				for (idx in sorted_idx) {
					commit = tasks[task][sorted_idx[idx]]
					if (isarray(upstream[commit]))
						for (upstream_id in upstream[commit])
							print "  - torvalds: " upstream[commit][upstream_id] " # " upstream_desc[commit][upstream_id] >> F
				}
				print "" >> F

				print "comments:" >> F
				for (idx in sorted_idx) {
					commit = tasks[task][sorted_idx[idx]]
					if (comment[commit])
						print "  - \"" commit ": " comment[commit] "\"" >> F
				}
			}
	}
' $SRC