@elisra-devops/docgen-data-provider 0.4.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,5 @@
1
+ sonar.sources=src
2
+ sonar.language=typescript
3
+ # sonar.javascript.lcov.reportPaths=coverage\SonarQube.xml
4
+ # sonar.typescript.lcov.reportPaths=coverage\SonarQube.xml
5
+ sonar.coverageReportPaths=coverage/SonarQube.xml
@@ -0,0 +1,21 @@
1
+ name: "🚀 ci"
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ build_and_test:
7
+ name: 🚀 build and test
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: 📚 checkout
11
+ uses: actions/checkout@v2
12
+ - name: 🟢 node
13
+ uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 14
16
+ registry-url: https://registry.npmjs.org
17
+ - run: npm install
18
+ - run: npm run build
19
+ env:
20
+ ORG_URL: ${{secrets.AZDO_ORG_URL}}
21
+ PAT: ${{secrets.AZDO_PAT}}
@@ -0,0 +1,40 @@
1
+ name: "🚀 publish"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+ packages: write
11
+
12
+ jobs:
13
+ release:
14
+ name: 🚀 publish
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - name: 📚 checkout
18
+ uses: actions/checkout@v2
19
+
20
+ - name: 🟢 node
21
+ uses: actions/setup-node@v2
22
+ with:
23
+ node-version: 14
24
+ registry-url: https://registry.npmjs.org
25
+
26
+ - run: npm install
27
+
28
+ - run: npm run build
29
+
30
+ - name: 'Automated Version Bump'
31
+ uses: 'phips28/gh-action-bump-version@master'
32
+ env:
33
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
+ with:
35
+ commit-message: 'CI: bumps version to {{version}} [skip ci]'
36
+
37
+ - name: 🚀 publish
38
+ run: npm publish --access public
39
+ env:
40
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Assaf Yacobi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # dg-data-provider-azuredevops
2
+
3
+ [![npm version](https://badge.fury.io/js/@doc-gen%2Fdg-data-provider-azuredevops.svg)](https://badge.fury.io/js/@doc-gen%2Fdg-data-provider-azuredevops)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ [![Chat on Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.com/channels/904432165901709333/904432165901709336)
8
+
9
+ An azuredevops data provider using the document generator interface.
10
+ supported modules:
11
+
12
+ - **managment** - a module for retriving general purpose data, for example: number of projects and projects detailes.
13
+ - **git** - a module for retriving git related data, for example: commit detailes, branches etc.
14
+ - **pipelines** - a module for retriving pipelines data, for example: pipline history, pipline details etc.
15
+ - **tests** - a module for retriving tests data, for example:testplans list, test steps etc.
16
+ - **tickets** - a module for retriving tickets data, for example: open tickets, tickets list by query results etc.
17
+
18
+ ### Installation:
19
+
20
+ ```
21
+ npm i @doc-gen/dg-data-provider-azuredevops
22
+ ```
23
+
24
+ ### Usage:
25
+
26
+ ```
27
+ import DgDataProviderAzureDevOps from "@doc-gen/dg-data-provider-azuredevops";
28
+
29
+ let dgDataProviderAzureDevOps = new DgDataProviderAzureDevOps(
30
+ orgUrl,
31
+ token
32
+ );
33
+ let gitDataProvider = await dgDataProviderAzureDevOps.getGitDataProvider();
34
+
35
+
36
+ ```
37
+
38
+ ### Contributors:
@@ -0,0 +1,12 @@
1
+ declare global {
2
+ namespace NodeJS {
3
+ interface ProcessEnv {
4
+ ORG_URL: string;
5
+ PAT: string;
6
+ }
7
+ }
8
+ }
9
+
10
+ // If this file has no import/export statements (i.e. is a script)
11
+ // convert it into a module by adding an empty export statement.
12
+ export {};
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@elisra-devops/docgen-data-provider",
3
+ "version": "0.4.6",
4
+ "description": "A document generator data provider, aimed to retrive data from azure devops",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/assafushy/dg-data-provider-azuredevops.git"
8
+ },
9
+ "private": false,
10
+ "main": "./bin/index.js",
11
+ "types": "./bin/index.d.ts",
12
+ "scripts": {
13
+ "test": "jest --coverage --runInBand --forceExit",
14
+ "build": "tsc"
15
+ },
16
+ "devDependencies": {
17
+ "@types/jest": "^25.2.1",
18
+ "@types/request": "^2.48.5",
19
+ "dotenv": "^10.0.0",
20
+ "jest": "^26.0.1",
21
+ "jest-junit": "^10.0.0",
22
+ "npm": "^6.14.5",
23
+ "ts-jest": "^25.5.1",
24
+ "typescript": "^3.6.3"
25
+ },
26
+ "dependencies": {
27
+ "@types/xml2js": "^0.4.5",
28
+ "axios": "^0.19.2",
29
+ "request": "^2.88.2",
30
+ "winston": "^3.2.1",
31
+ "winston-transport-browserconsole": "^1.0.5",
32
+ "xml2js": "^0.4.23"
33
+ },
34
+ "jest": {
35
+ "preset": "ts-jest",
36
+ "testPathIgnorePatterns": [
37
+ "/bin/"
38
+ ],
39
+ "reporters": [
40
+ "default",
41
+ "jest-junit"
42
+ ]
43
+ },
44
+ "jest-junit": {
45
+ "output": "./junit.xml"
46
+ },
47
+ "author": "",
48
+ "license": "ISC",
49
+ "bugs": {
50
+ "url": "https://github.com/assafushy/dg-data-provider-azuredevops/issues"
51
+ },
52
+ "homepage": "https://github.com/assafushy/dg-data-provider-azuredevops#readme"
53
+ }
@@ -0,0 +1,117 @@
1
+ import { Query, Workitem } from "../models/tfs-data";
2
+
3
+ export class suiteData {
4
+ name: string;
5
+ id: string;
6
+ parent: string;
7
+ level: number;
8
+ url: string;
9
+ constructor(name: string, id: string, parent: string, level: number) {
10
+ this.name = name;
11
+ this.id = id;
12
+ this.parent = parent;
13
+ this.level = level;
14
+ }
15
+ }
16
+ export class Relations {
17
+ id: string;
18
+ rels: Array<string> = new Array<string>();
19
+ }
20
+
21
+ export class Links {
22
+ id: string;
23
+ title: string;
24
+ description: string;
25
+ url: string;
26
+ type: string;
27
+ customerId: string;
28
+ }
29
+ export class Trace {
30
+ id: string;
31
+ title: string;
32
+ url: string;
33
+ customerId: string;
34
+ links: Array<Links>;
35
+ }
36
+
37
+ export class Helper {
38
+ static level: number = 1;
39
+ static first: boolean = true;
40
+ static buildSuiteslevel(dataSuites: any): any {}
41
+ public static suitList: Array<suiteData> = new Array<suiteData>();
42
+ public static findSuitesRecursive(
43
+ planId: string,
44
+ url: string,
45
+ project: string,
46
+ suits: any,
47
+ foundId: string,
48
+ recursive: boolean
49
+ ): Array<suiteData> {
50
+ for (let i = 0; i < suits.length; i++) {
51
+ if (suits[i].parentSuiteId != 0) {
52
+ if (suits[i].parentSuiteId == foundId) {
53
+ let suit: suiteData = new suiteData(
54
+ suits[i].title,
55
+ suits[i].id,
56
+ foundId,
57
+ this.level++
58
+ );
59
+ suit.url =
60
+ url +
61
+ project +
62
+ "/_testManagement?planId=" +
63
+ planId +
64
+ "&suiteId=" +
65
+ suits[i].id +
66
+ "&_a=tests";
67
+ this.suitList.push(suit);
68
+ if (recursive == false) {
69
+ return this.suitList;
70
+ }
71
+ this.findSuitesRecursive(
72
+ planId,
73
+ url,
74
+ project,
75
+ suits,
76
+ suits[i].id,
77
+ true
78
+ );
79
+ this.level--;
80
+ }
81
+ } else {
82
+ if (suits[i].id == foundId && Helper.first) {
83
+ let suit: suiteData = new suiteData(
84
+ suits[i].title,
85
+ suits[i].id,
86
+ foundId,
87
+ this.level
88
+ );
89
+ suit.url = url + project + "/_workitems/edit/" + suits[i].id;
90
+ Helper.first = false;
91
+ if (recursive == false) {
92
+ return this.suitList;
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return this.suitList;
98
+ }
99
+ public static levelList: Array<Workitem> = new Array<Workitem>();
100
+ public static LevelBuilder(results: Query, foundId: string): Array<Workitem> {
101
+ for (let i = 0; i < results.workItems.length; i++) {
102
+ if (results.workItems[i].Source == 0) {
103
+ results.workItems[i].level = 0;
104
+ if (!this.levelList.includes(results.workItems[i]))
105
+ this.levelList.push(results.workItems[i]);
106
+ } else if (results.workItems[i].Source.toString() == foundId) {
107
+ results.workItems[i].level = this.level++;
108
+ this.levelList.push(results.workItems[i]);
109
+
110
+ this.LevelBuilder(results, results.workItems[i].fields[0].value);
111
+ this.level--;
112
+ }
113
+ }
114
+
115
+ return this.levelList;
116
+ }
117
+ }
@@ -0,0 +1,92 @@
1
+ import axios from "axios";
2
+ import logger from "../utils/logger";
3
+ import * as request from "request";
4
+
5
+ export class TFSServices {
6
+ public static async downloadZipFile(url: string, pat: string): Promise<any> {
7
+ let json;
8
+ try {
9
+ var d = {
10
+ request: {
11
+ method: "getUser",
12
+ auth: {
13
+ username: "",
14
+ password: `${pat}`,
15
+ },
16
+ },
17
+ };
18
+ let res = await request({
19
+ url: url,
20
+ headers: { "Content-Type": "application/zip" },
21
+ auth: {
22
+ username: "",
23
+ password: pat,
24
+ },
25
+ encoding: null,
26
+ });
27
+ return res;
28
+ } catch (e) {
29
+ logger.error(`error download zip file , url : ${url}`);
30
+ throw new Error(String(e));
31
+ }
32
+ }
33
+
34
+ public static async getItemContent(
35
+ url: string,
36
+ pat: string,
37
+ requestMethod: string = "get",
38
+ data: any = {},
39
+ customHeaders: any = {}
40
+ ): Promise<any> {
41
+ let config: any = {
42
+ headers: customHeaders,
43
+ method: requestMethod,
44
+ auth: {
45
+ username: "",
46
+ password: pat,
47
+ },
48
+ data: data,
49
+ };
50
+ let json;
51
+ logger.silly(`making request:
52
+ url: ${url}
53
+ config: ${JSON.stringify(config)}`);
54
+ try {
55
+ let result = await axios(url, config);
56
+ json = JSON.parse(JSON.stringify(result.data));
57
+ } catch (e) {
58
+ logger.error(`error making request to azure devops , url : ${url}`);
59
+ // logger.error(JSON.stringify(e.data));
60
+ }
61
+ return json;
62
+ }
63
+
64
+ public static async postRequest(
65
+ url: string,
66
+ pat: string,
67
+ requestMethod: string = "post",
68
+ data: any,
69
+ customHeaders: any = {}
70
+ ): Promise<any> {
71
+ let config: any = {
72
+ headers: customHeaders,
73
+ method: requestMethod,
74
+ auth: {
75
+ username: "",
76
+ password: pat,
77
+ },
78
+ data: data,
79
+ };
80
+ let result;
81
+ logger.silly(`making request:
82
+ url: ${url}
83
+ config: ${JSON.stringify(config)}`);
84
+ try {
85
+ result = await axios(url, config);
86
+ } catch (e) {
87
+ logger.error(`error making post request to azure devops`);
88
+ console.log(e);
89
+ }
90
+ return result;
91
+ }
92
+ }
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ import MangementDataProvider from './modules/MangementDataProvider'
2
+ import TicketsDataProvider from './modules/TicketsDataProvider'
3
+ import GitDataProvider from "./modules/GitDataProvider";
4
+ import PipelinesDataProvider from './modules/PipelinesDataProvider'
5
+ import TestDataProvider from './modules/TestDataProvider'
6
+
7
+ import logger from "./utils/logger";
8
+
9
+ export default class DgDataProviderAzureDevOps {
10
+ orgUrl: string = "";
11
+ token: string = "";
12
+ apiVersion: string;
13
+
14
+
15
+ constructor(orgUrl: string, token: string, apiVersion?: string) {
16
+ this.orgUrl = orgUrl;
17
+ this.token = token;
18
+ logger.info(`azure devops data provider initilized`);
19
+ }
20
+
21
+ async getMangementDataProvider() : Promise<MangementDataProvider> {
22
+ return new MangementDataProvider(this.orgUrl, this.token);
23
+ }
24
+ async getTicketsDataProvider() : Promise<TicketsDataProvider> {
25
+ return new TicketsDataProvider(this.orgUrl, this.token);
26
+ }
27
+ async getGitDataProvider() : Promise<GitDataProvider> {
28
+ return new GitDataProvider(this.orgUrl, this.token);
29
+ }
30
+ async getPipelinesDataProvider() : Promise<PipelinesDataProvider> {
31
+ return new PipelinesDataProvider(this.orgUrl, this.token);
32
+ }
33
+ async getTestDataProvider() : Promise<TestDataProvider> {
34
+ return new TestDataProvider(this.orgUrl, this.token);
35
+ }
36
+ } //class
@@ -0,0 +1,137 @@
1
+
2
+ export class QueryAllTypes {
3
+ q: Query;
4
+ source: number;
5
+ }
6
+
7
+ export class Query {
8
+ queryType: QueryType;
9
+ queryResultType: QueryResultType;
10
+ asOf: Date;
11
+ columns: Column[] = new Array<Column>();
12
+ //sortColumns: Sortcolumn[] =new Array<Sortcolumn>()
13
+ workItems: Workitem[] = new Array<Workitem>();
14
+ }
15
+ class QueryTree {
16
+ queryType: QueryType;
17
+ queryResultType: QueryResultType;
18
+ asOf: Date;
19
+ columns: Column[] = new Array<Column>();
20
+ //sortColumns: Sortcolumn[] =new Array<Sortcolumn>()
21
+ workItems: Workitemrelation[] = new Array<Workitemrelation>();
22
+ }
23
+
24
+ export class Column {
25
+ referenceName: string;
26
+ name: string;
27
+ url: string;
28
+ }
29
+
30
+ class Sortcolumn {
31
+ field: Field;
32
+ descending: boolean;
33
+ }
34
+
35
+ class Field {
36
+ referenceName: string;
37
+ name: string;
38
+ url: string;
39
+ }
40
+
41
+ export class Workitem {
42
+ id: number;
43
+ url: string;
44
+ parentId: number;
45
+ fields: value[];
46
+ Source: number = 0;
47
+ attachments: any[];
48
+ level:number;
49
+ }
50
+ export class value {
51
+ name: string;
52
+ value: string;
53
+ }
54
+ enum QueryResultType {
55
+ WorkItem = 1,
56
+ WorkItemLink = 2
57
+ }
58
+ export enum QueryType {
59
+ Flat = "flat",
60
+ Tree = "tree",
61
+ OneHop = "oneHop"
62
+ }
63
+
64
+ class Workitemrelation {
65
+ rel: string;
66
+ source: Source;
67
+ target: Target;
68
+ }
69
+
70
+ class Workrelation {
71
+ relation: Workitemrelation;
72
+ value: value;
73
+ }
74
+
75
+ class Source {
76
+ id: number;
77
+ url: string;
78
+ }
79
+
80
+ class Target {
81
+ id: number;
82
+ url: string;
83
+ }
84
+
85
+ export interface Comment {
86
+ parentCommentId: number;
87
+ content: string;
88
+ commentType: number;
89
+ }
90
+
91
+ export interface RightFileEnd {
92
+ line: number;
93
+ offset: number;
94
+ }
95
+
96
+ export interface RightFileStart {
97
+ line: number;
98
+ offset: number;
99
+ }
100
+
101
+ export interface ThreadContext {
102
+ filePath: string;
103
+ leftFileEnd?: any;
104
+ leftFileStart?: any;
105
+ rightFileEnd: RightFileEnd;
106
+ rightFileStart: RightFileStart;
107
+ }
108
+
109
+ export interface IterationContext {
110
+ firstComparingIteration: number;
111
+ secondComparingIteration: number;
112
+ }
113
+
114
+ export interface PullRequestThreadContext {
115
+ changeTrackingId: number;
116
+ iterationContext: IterationContext;
117
+ }
118
+
119
+ export interface RootObject {
120
+ comments: Comment[];
121
+ status: number;
122
+ threadContext: ThreadContext;
123
+ pullRequestThreadContext: PullRequestThreadContext;
124
+ }
125
+ export class TestCase {
126
+ id:String;
127
+ title:String;
128
+ description:String;
129
+ area: String;
130
+ steps: TestSteps[];
131
+ suit: string;
132
+ url:string;
133
+ }
134
+ export class TestSteps {
135
+ action: String;
136
+ expected: String;
137
+ }