@addev-be/framework-utils 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import {
2
+ createJiraVersionInApi,
3
+ getJiraProjectIdFromApi,
4
+ } from './helpers/jira.mjs';
5
+
6
+ export const createJiraVersion = async (
7
+ jiraUrl,
8
+ projectKey,
9
+ version,
10
+ email,
11
+ token
12
+ ) => {
13
+ const projectId = await getJiraProjectIdFromApi(
14
+ jiraUrl,
15
+ projectKey,
16
+ email,
17
+ token
18
+ );
19
+ if (!projectId) {
20
+ throw new Error(`Could not find Jira project with key ${projectKey}`);
21
+ }
22
+ const success = await createJiraVersionInApi(
23
+ jiraUrl,
24
+ projectId,
25
+ version,
26
+ email,
27
+ token
28
+ );
29
+ if (!success) {
30
+ throw new Error(`Could not create Jira version ${version}`);
31
+ }
32
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Get Jira Project ID from Project Key
3
+ * @param {string} jiraUrl
4
+ * @param {string} projectKey
5
+ * @returns
6
+ */
7
+ export const getJiraProjectIdFromApi = async (
8
+ jiraUrl,
9
+ projectKey,
10
+ email,
11
+ token
12
+ ) => {
13
+ const response = await fetch(
14
+ `${jiraUrl.trimEnd('/')}/rest/api/3/project/${projectKey}`,
15
+ {
16
+ method: 'GET',
17
+ headers: {
18
+ Authorization: `Basic ${Buffer.from(email + ':' + token).toString(
19
+ 'base64'
20
+ )}`,
21
+ Accept: 'application/json',
22
+ },
23
+ }
24
+ ).then((response) => response.json());
25
+
26
+ return response.id;
27
+ };
28
+
29
+ export const createJiraVersionInApi = async (
30
+ jiraUrl,
31
+ projectId,
32
+ name,
33
+ email,
34
+ token
35
+ ) => {
36
+ const response = await fetch(`${jiraUrl.trimEnd('/')}/rest/api/3/version`, {
37
+ method: 'POST',
38
+ headers: {
39
+ Authorization: `Basic ${Buffer.from(email + ':' + token).toString(
40
+ 'base64'
41
+ )}`,
42
+ Accept: 'application/json',
43
+ 'Content-Type': 'application/json',
44
+ },
45
+ body: JSON.stringify({
46
+ archived: false,
47
+ description: `GitLab release ${name}`,
48
+ name,
49
+ projectId,
50
+ releaseDate: new Date().toISOString().split('T')[0],
51
+ released: false,
52
+ }),
53
+ });
54
+
55
+ return response.ok;
56
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/framework-utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "type": "module",
5
5
  "export": {
6
6
  "node": {