-
Notifications
You must be signed in to change notification settings - Fork 2
/
new.php
178 lines (140 loc) · 4.48 KB
/
new.php
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
require 'inc.bootstrap.php';
do_logincheck();
if ( isset($_POST['preview']) ) {
$rsp = jira_post(JIRA_API_1_PATH . 'render', array(
'issueKey' => $_POST['issue'] ?? '',
'rendererType' => 'atlassian-wiki-renderer',
'unrenderedMarkup' => trim($_POST['preview']),
), $error, $info);
if ( $error ) {
echo '<pre>';
var_dump($error);
print_r($rsp);
print_r($info);
}
else {
echo do_remarkup($rsp);
}
exit;
}
if ( isset($_GET['project'], $_GET['issuetype'], $_POST['summary'], $_POST['description'], $_POST['priority']) ) {
$fields = array(
'project' => array('id' => $_GET['project']),
'issuetype' => array('id' => $_GET['issuetype']),
'summary' => trim($_POST['summary']),
'description' => trim($_POST['description']),
'priority' => array('id' => $_POST['priority']),
);
if ( !empty($_POST['parent']) ) {
$fields['parent'] = array('key' => $_POST['parent']);
}
$response = jira_post('issue', compact('fields'), $error, $info);
if ( !$error ) {
$key = $response->key;
return do_redirect('issue', compact('key'));
}
echo '<pre>';
print_r($fields);
var_dump($error);
print_r($response);
print_r($info);
exit;
}
$project = @$_GET['project'];
$issuetype = @$_GET['issuetype'];
$parent = (string)@$_GET['parent'];
$parentsummary = (string)@$_GET['parentsummary'];
$_title = 'New issue';
include 'tpl.header.php';
echo '<h1>Create new issue</h1>';
// Show parent issue
if ( $parent && $parentsummary ) {
echo '<h2>Parent issue</h2>';
echo '<ul>';
echo '<li>';
echo '<a href="issue.php?key=' . urlencode($parent) . '">' . html($parent) . ' ' . html($parentsummary) . '</a>';
echo '</li>';
echo '</ul>';
}
// Choose project
echo '<h2>Project</h2>';
if ( !$project ) {
$projects = jira_get('project', array(), $error, $info);
echo '<ul>';
foreach ( $projects AS $project ) {
echo '<li>';
echo '<a href="new.php?project=' . $project->id . '">' . html($project->name) . '</a>';
echo '</li>';
}
echo '</ul>';
exit;
}
// Get project meta data
$meta = jira_get('issue/createmeta', array(
'expand' => 'projects.issuetypes.fields',
'projectIds' => $project,
'issuetypeIds' => $issuetype ?: null,
), $error, $info);
$project = $meta->projects[0];
// Show selected project
echo '<ul>';
echo '<li>';
echo '<a href="new.php?project=' . $project->id . '">' . html($project->name) . '</a>';
echo ' (<a href="new.php?parent=' . urlencode($parent) . '">change</a>)';
echo '</li>';
echo '</ul>';
// Choose issue type
echo '<h2>Issue type</h2>';
if ( !$issuetype ) {
echo '<ul>';
$subtask = !empty($parent);
foreach ( $project->issuetypes AS $issuetype ) {
if ( $issuetype->subtask == $subtask ) {
echo '<li>';
echo '<a href="new.php?project=' . $project->id . '&issuetype=' . $issuetype->id . '&parent=' . urlencode($parent) . '&parentsummary=' . urlencode($parentsummary) . '">' . $issuetype->name . '</a>';
echo '</li>';
}
}
echo '</ul>';
exit;
}
// Get issue type meta data
$issuetype = get_issuetype($project, $issuetype);
// Show selected issue type
echo '<ul>';
echo '<li>';
echo '<a href="new.php?project=' . $project->id . '&issuetype=' . $issuetype->id . '">' . $issuetype->name . '</a>';
echo ' (<a href="new.php?project=' . $project->id . '&parent=' . urlencode($parent) . '&parentsummary=' . urlencode($parentsummary) . '">change</a>)';
echo '</li>';
echo '</ul>';
// Get priority meta data
$priorities = array_reduce($issuetype->fields->priority->allowedValues, function($list, $priority) {
$list[ $priority->id ] = $priority->name;
return $list;
});
$priorityKeys = array_keys($priorities);
$defaultPriority = $priorityKeys[ floor((count($priorities) - 1) / 2) ];
?>
<form autocomplete="off" action method="post">
<? if ($parent && $parentsummary): ?>
<input type="hidden" name="parent" value="<?= html($parent) ?>" />
<p>Parent issue: <input readonly disabled value="<?= html($parent . ' ' . $parentsummary) ?>" /></p>
<? endif ?>
<p>Summary: <input name="summary" /></p>
<p>Description: <textarea name="description" rows="8"></textarea><br><button type="button" data-preview="textarea[name=description]">Preview</button></p>
<p>Priority: <select name="priority"><?= html_options($priorities, $defaultPriority) ?></select></p>
<p><button>Save</button></p>
</form>
<?php
if ( isset($_GET['debug']) ) {
echo '<pre>' . print_r($issuetype, 1) . '</pre>';
}
include 'tpl.footer.php';
function get_issuetype( $project, $is_issuetype ) {
foreach ( $project->issuetypes AS $issuetype ) {
if ( $issuetype->id == $is_issuetype ) {
return $issuetype;
}
}
}