-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBacklog.gs
More file actions
199 lines (180 loc) · 4.98 KB
/
Backlog.gs
File metadata and controls
199 lines (180 loc) · 4.98 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
* Backlog API クラス
*/
function Backlog(param) {
this.host = param.host;
this.url = 'https://' + param.host;
this.apiKey = param.apiKey;
this.project = null;
this.oUrl = new Url();
}
/**
* 名称に対応するソートキーを取得
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-issue-list/
*/
Backlog.prototype.getSortKey = function(name) {
var sortKeys = {
"ID" : "id",
"親ID" : "parentIssueId",
"種別" : "issueType",
"キー" : null,
"件名" : "summary",
"担当者" : "assignee",
"状態" : "status",
"完了理由" : "resolution",
"優先度" : "priority",
"カテゴリー" : "category",
"マイルストーン" : "milestone",
"登録日" : "created",
"期限日" : "dueDate",
"更新日" : "updated",
"登録者" : "createdUser",
};
return sortKeys[name];
};
/**
* Hostを取得
*/
Backlog.prototype.getHost = function() {
return this.host;
};
/**
* Projectの設定
* プロジェクトごとの処理を行うため
*/
Backlog.prototype.setProject = function(project) {
this.project = project;
};
/**
* スペースリンクの取得
*/
Backlog.prototype.buildUrlSpace = function() {
return this.url + '/dashboard';
};
/**
* Projectリンクの取得
*/
Backlog.prototype.buildUrlProject = function(projectKey) {
var key = '';
// 指定値優先
if (projectKey !== undefined) {
key = projectKey;
}
// 次に、インスタンス変数が有ったら
else if (this.project.projectKey != null) {
key = this.project.projectKey;
}
else {
throw new Error("projectKey が設定されていません。")
}
return this.url + '/projects/' + key;
};
/**
* 課題リンクの取得
*/
Backlog.prototype.buildUrlIssue = function(issueKey) {
return this.url + '/view/' + issueKey;
};
/**
* カテゴリーリンクの取得
* setProjectを先にコールする事
*/
Backlog.prototype.buildUrlCetegory = function(categoryId) {
// インスタンス変数から
if (this.project.projectKey == null) {
throw new Error("this.projectKey が設定されていません。")
}
return this.url + '/find/' + this.project.projectKey + '?condition.componentId=' + categoryId;
};
/**
* マイルストーンリンクの取得
* setProjectを先にコールする事
*/
Backlog.prototype.buildUrlVersion = function(versionId) {
// インスタンス変数から
if (this.project.projectKey == null) {
throw new Error("this.projectKey が設定されていません。")
}
return this.url + '/find/' + this.project.projectKey + '?condition.fixedVersionId=' + versionId;
};
/**
* Backlogへのリクエスト共通関数
* @protected
* @see https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
*/
Backlog.prototype.request = function(url, queryStrings) {
if (queryStrings === undefined) {
queryStrings = {};
}
queryStrings.apiKey = this.apiKey;
var json = this.oUrl.fetch(url, queryStrings);
return JSON.parse(json);
}
/**
* スペース情報の取得
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-space/
*/
Backlog.prototype.getSpace = function(params) {
var url = this.url + '/api/v2/space';
return this.request(url);
};
/**
* プロジェクト一覧の取得
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-project-list/
*/
Backlog.prototype.getProjects = function(params) {
var url = this.url + '/api/v2/projects';
return this.request(url, {
archived: (params.archived) ? null : false, // 全て or 非アーカイブ
// 管理者権限の場合のみ、有効
// all : true, // 全てのプロジェクト
});
};
/**
* 課題一覧の取得
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-issue-list/
*/
Backlog.prototype.getIssues = function(params) {
var projectId = [];
var url = this.url + '/api/v2/issues';
// 指定値優先
if (params.projectId !== undefined) {
projectId = params.projectId;
}
// 無ければ設定された値
else if (this.project.id !== undefined) {
projectId.push(this.project.id);
}
return this.request(url, {
projectId: projectId,
order : params.order,
sort : params.sort,
statusId : params.statusId,
offset : params.offset,
count : params.count,
updatedSince : params.updatedSince,
updatedUntil : params.updatedUntil,
});
};
/**
* 課題情報の取得
* @note not used
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-issue/
*/
Backlog.prototype.getIssue = function(issueIdOrKey) {
var url = this.url + '/api/v2/issues/' + issueIdOrKey;
return this.request(url);
};
/**
* 課題コメントの取得
* @see https://developer.nulab-inc.com/ja/docs/backlog/api/2/get-comment-list/
*/
Backlog.prototype.getIssueComments = function(issueIdOrKey, params) {
var url = this.url + '/api/v2/issues/' + issueIdOrKey + '/comments';
return this.request(url, {
minId : null,
maxId : null,
count : params.count,
order : params.order,
});
};