Skip to content

Commit c15cdc2

Browse files
author
sunlei
committed
jira datasource
1 parent 5942341 commit c15cdc2

File tree

1 file changed

+37
-23
lines changed
  • server/node-service/src/plugins/jira

1 file changed

+37
-23
lines changed

server/node-service/src/plugins/jira/index.ts

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
import { readFileSync } from "fs";
12
import _ from "lodash";
2-
import { OpenAPIV3, OpenAPI } from "openapi-types";
3-
import { ConfigToType, DataSourcePlugin } from "openblocks-sdk/dataSource";
3+
import { OpenAPI } from "openapi-types";
4+
import { ConfigToType, DataSourcePlugin, QueryConfig } from "openblocks-sdk/dataSource";
5+
import path from "path";
46
import { runOpenApi } from "../openApi";
57
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
68

7-
import spec from "./jira.spec.json";
9+
const specJson = readFileSync(path.join(__dirname, "./jira.spec.json")).toString();
810

911
const dataSourceConfig = {
1012
type: "dataSource",
1113
params: [
14+
{
15+
type: "textInput",
16+
key: "serverUrl",
17+
label: "Server URL",
18+
placeholder: "https://your-domain.atlassian.net",
19+
},
1220
{
1321
type: "groupTitle",
1422
key: "basicAuth",
@@ -17,16 +25,16 @@ const dataSourceConfig = {
1725
{
1826
type: "textInput",
1927
key: "basicAuth.username",
20-
label: "Username",
21-
tooltip: "Basic auth username",
22-
placeholder: "<Basic Auth Username>",
28+
label: "Account Email",
29+
tooltip: "The email of your atlassian account",
30+
placeholder: "<The email of your atlassian account>",
2331
},
2432
{
2533
type: "password",
2634
key: "basicAuth.password",
27-
label: "Password",
35+
label: "Api Token",
2836
tooltip: "Basic auth password",
29-
placeholder: "<Basic Auth Password>",
37+
placeholder: "<API Token>",
3038
},
3139
],
3240
} as const;
@@ -35,38 +43,44 @@ const parseOptions: ParseOpenApiOptions = {
3543
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
3644
return _.upperFirst(operation.operationId || "");
3745
},
46+
actionDescription(method, path, operation) {
47+
return operation.description || "";
48+
},
3849
};
3950

4051
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
4152

53+
let queryConfig: QueryConfig;
54+
4255
const jiraPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
4356
id: "jira",
4457
name: "Jira",
4558
icon: "jira.svg",
4659
category: "api",
4760
dataSourceConfig,
4861
queryConfig: async () => {
49-
const { actions, categories } = await parseOpenApi(
50-
spec as unknown as OpenAPI.Document,
51-
parseOptions
52-
);
53-
return {
54-
type: "query",
55-
label: "Action",
56-
categories: {
57-
label: "Category",
58-
items: categories,
59-
},
60-
actions,
61-
};
62+
if (!queryConfig) {
63+
const { actions, categories } = await parseOpenApi(JSON.parse(specJson), parseOptions);
64+
queryConfig = {
65+
type: "query",
66+
label: "Action",
67+
categories: {
68+
label: "Category",
69+
items: categories,
70+
},
71+
actions,
72+
};
73+
}
74+
return queryConfig;
6275
},
6376
run: function (actionData, dataSourceConfig): Promise<any> {
77+
const spec = JSON.parse(specJson);
6478
const runApiDsConfig = {
6579
url: "",
66-
serverURL: "",
80+
serverURL: dataSourceConfig.serverUrl,
6781
dynamicParamsConfig: dataSourceConfig,
6882
};
69-
return runOpenApi(actionData, runApiDsConfig, spec as unknown as OpenAPIV3.Document);
83+
return runOpenApi(actionData, runApiDsConfig, spec);
7084
},
7185
};
7286

0 commit comments

Comments
 (0)