backstage

Форк
0
173 строки · 4.8 Кб
1
/*
2
 * Copyright 2021 The Backstage Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
import { Entity } from '@backstage/catalog-model';
18
import { createDevApp, EntityGridItem } from '@backstage/dev-utils';
19
import React from 'react';
20
import { EntityBitriseContent } from '../src';
21
import { BitriseApi } from '../src/api/bitriseApi';
22
import {
23
  BitriseBuildArtifact,
24
  BitriseBuildArtifactDetails,
25
  BitriseBuildResult,
26
  BitrisePagingResponse,
27
} from '../src/api/bitriseApi.model';
28
import { BITRISE_APP_ANNOTATION } from '../src/components/BitriseBuildsComponent';
29
import { bitriseApiRef } from '../src/plugin';
30
import { Content, Header, Page } from '@backstage/core-components';
31

32
const mockedPagingResponse: BitrisePagingResponse = {
33
  next: 'fae3232de3d2',
34
  page_item_limit: 20,
35
  total_item_count: 400,
36
};
37

38
const entities: (string | undefined)[] = [
39
  'builds',
40
  'searchBuilds',
41
  'searchNotFound',
42
  'empty',
43
  'error',
44
  'never',
45
  undefined,
46
];
47

48
const mockedBuildResults: BitriseBuildResult[] = [
49
  {
50
    appSlug: 'ios-app',
51
    buildSlug: '3291j9390d39239d3',
52
    commitHash: '27c988e4f13e26bc2d1b0af292026a3079aqsxe1',
53
    id: 29525,
54
    message: 'develop',
55
    source:
56
      'https://github.com/ORG/APPNAME/commit/27c988e4f13e26bc2d1b0af292026a3079aqsxe1',
57
    statusText: 'success',
58
    status: 1,
59
    workflow: 'app-ios-test',
60
    triggerTime: '2019-01-27T17:55:17Z',
61
    duration: '12 minutes',
62
  },
63
  {
64
    appSlug: 'ios-app',
65
    buildSlug: '38i23sk2923js9231s1',
66
    commitHash: '13c988d4f13e06bcdd1b0af292086a3079cdaxb0',
67
    id: 19523,
68
    message: 'main',
69
    source:
70
      'https://github.com/ORG/APPNAME/commit/13c988d4f13e06bcdd1b0af292086a3079cdaxb0',
71
    statusText: 'in-progress',
72
    status: 0,
73
    workflow: 'app-ios-release',
74
    triggerTime: '2020-01-28T17:55:17Z',
75
    duration: '19 minutes',
76
  },
77
];
78
const entity = (name?: string) =>
79
  ({
80
    apiVersion: 'backstage.io/v1alpha1',
81
    kind: 'Component',
82
    metadata: {
83
      annotations: {
84
        [BITRISE_APP_ANNOTATION]: name,
85
      },
86
      name: name,
87
    },
88
  } as Entity);
89

90
createDevApp()
91
  .registerApi({
92
    api: bitriseApiRef,
93
    deps: {},
94
    factory: () =>
95
      ({
96
        getBuilds: async (appName: string) => {
97
          switch (appName) {
98
            case 'error':
99
              throw new Error('Error!');
100

101
            case 'never':
102
              return new Promise(() => {});
103

104
            case 'builds':
105
              return { data: mockedBuildResults, paging: mockedPagingResponse };
106

107
            case 'searchBuilds':
108
              return {
109
                data: [mockedBuildResults.find(b => b.message === 'develop')],
110
                paging: mockedPagingResponse,
111
              };
112

113
            case 'searchNotFound':
114
              return [];
115

116
            default:
117
              return undefined;
118
          }
119
        },
120
        getBuildWorkflows: async (_buildSlug: string) => {
121
          return ['app-ios-release', 'app-ios-test'];
122
        },
123
        getApp: async (_appName: string) => {
124
          return {
125
            slug: _appName,
126
          };
127
        },
128
        getBuildArtifacts: async (_appName: string, _buildSlug: string) => {
129
          return [
130
            {
131
              title: 'App artifact',
132
              slug: 'some-artifact-slug',
133
            },
134
            {
135
              title: 'App artifact 2',
136
              slug: 'some-artifact-slug-2',
137
            },
138
            {
139
              title: 'App artifact 3',
140
              slug: 'some-artifact-slug-3',
141
            },
142
          ] as BitriseBuildArtifact[];
143
        },
144
        getArtifactDetails: async (
145
          _appName: string,
146
          _buildSlug: string,
147
          _artifactSlug: string,
148
        ) => {
149
          return {
150
            title: 'App artifact',
151
            slug: 'some-artifact-slug',
152
            public_install_page_url: 'some-url',
153
            expiring_download_url: 'some-url',
154
          } as BitriseBuildArtifactDetails;
155
        },
156
      } as BitriseApi),
157
  })
158
  .addPage({
159
    title: 'Bitrise CI',
160
    element: (
161
      <Page themeId="home">
162
        <Header title="Bitrise CI" />
163
        <Content>
164
          {entities.map(entityItem => (
165
            <EntityGridItem entity={entity(entityItem)} key={entityItem}>
166
              <EntityBitriseContent />
167
            </EntityGridItem>
168
          ))}
169
        </Content>
170
      </Page>
171
    ),
172
  })
173
  .render();
174

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.