gitlab-radiator 3.3.9 → 3.3.10

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.
@@ -1,94 +0,0 @@
1
- import 'core-js/stable'
2
- import 'regenerator-runtime/runtime'
3
-
4
- import type {GlobalState, Project} from './gitlab-types'
5
- import {argumentsFromDocumentUrl} from './arguments'
6
- import {GroupedProjects} from './groupedProjects'
7
- import React from 'react'
8
- import ReactDOM from 'react-dom'
9
-
10
- class RadiatorApp extends React.Component<unknown, GlobalState> {
11
- public args: {override: {columns?: number, zoom?: number}, includedTags: string[] | null, screen: {id: number, total: number}}
12
-
13
- constructor(props: unknown) {
14
- super(props)
15
- this.state = {
16
- columns: 1,
17
- error: null,
18
- groupSuccessfulProjects: false,
19
- projects: null,
20
- projectsOrder: [],
21
- now: 0,
22
- zoom: 1
23
- }
24
-
25
- this.args = argumentsFromDocumentUrl()
26
- }
27
-
28
- componentDidMount = () => {
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- const socket = (window as any).io()
31
- socket.on('state', this.onServerStateUpdated.bind(this))
32
- socket.on('disconnect', this.onDisconnect.bind(this))
33
- }
34
-
35
- render = () =>
36
- <div>
37
- {this.renderErrorMessage()}
38
- {this.renderProgressMessage()}
39
-
40
- {this.state.projects &&
41
- <GroupedProjects now={this.state.now} zoom={this.state.zoom} columns={this.state.columns}
42
- projects={this.state.projects} projectsOrder={this.state.projectsOrder}
43
- groupSuccessfulProjects={this.state.groupSuccessfulProjects}
44
- screen={this.args.screen}/>
45
- }
46
- </div>
47
-
48
- renderErrorMessage = () =>
49
- this.state.error && <div className="error">{this.state.error}</div>
50
-
51
- renderProgressMessage = () => {
52
- if (!this.state.projects) {
53
- return <h2 className="loading">Fetching projects and CI pipelines from GitLab...</h2>
54
- } else if (this.state.projects.length === 0) {
55
- return <h2 className="loading">No projects with CI pipelines found.</h2>
56
- }
57
- return null
58
- }
59
-
60
- onServerStateUpdated = (state: GlobalState) => {
61
- this.setState({
62
- ...state,
63
- ...this.args.override,
64
- projects: this.filterProjectsByTags(state.projects)
65
- })
66
- }
67
-
68
- onDisconnect = () => this.setState({error: 'gitlab-radiator server is offline'})
69
-
70
- filterProjectsByTags = (projects: Project[] | null) => {
71
- if (projects === null) {
72
- return null
73
- }
74
-
75
- // No tag list specified, include all projects
76
- if (!this.args.includedTags) {
77
- return projects
78
- }
79
- // Empty tag list specified, include projects without tags
80
- if (this.args.includedTags.length === 0) {
81
- return projects.filter(project =>
82
- project.tags.length === 0
83
- )
84
- }
85
- // Tag list specified, include projects which have at least one of them
86
- return projects.filter(project =>
87
- project.tags.some(tag => this.args.includedTags?.includes(tag))
88
- )
89
- }
90
- }
91
-
92
- ReactDOM.render(<RadiatorApp/>, document.getElementById('app'))
93
-
94
- module.hot?.accept()
@@ -1,16 +0,0 @@
1
- import type {Pipeline} from './gitlab-types'
2
- import React from 'react'
3
- import {renderTimestamp} from './renderTimestamp'
4
-
5
- export function Info({pipeline, now}: {pipeline: Pipeline, now: number}): JSX.Element {
6
- return <div className="pipeline-info">
7
- <div>
8
- <span>{pipeline.commit ? pipeline.commit.author : '-'}</span>
9
- <span>{pipeline.commit ? `'${pipeline.commit.title}'` : '-'}</span>
10
- </div>
11
- <div>
12
- <span>{renderTimestamp(pipeline.stages, now)}</span>
13
- <span>on {pipeline.ref}</span>
14
- </div>
15
- </div>
16
- }
@@ -1,56 +0,0 @@
1
- import type {Job, JobStatus} from './gitlab-types'
2
- import _ from 'lodash'
3
- import React from 'react'
4
-
5
- const NON_BREAKING_SPACE = '\xa0'
6
-
7
- const JOB_STATES_IN_INTEREST_ORDER: JobStatus[] = [
8
- 'failed',
9
- 'running',
10
- 'created',
11
- 'pending',
12
- 'success',
13
- 'skipped'
14
- ]
15
-
16
- export function Jobs({jobs, maxNonFailedJobsVisible}: {jobs: Job[], maxNonFailedJobsVisible: number}): JSX.Element {
17
- const [failedJobs, nonFailedJobs] = _.partition(jobs, {status: 'failed'})
18
- const filteredJobs = sortByOriginalOrder(
19
- failedJobs.concat(
20
- _.orderBy(nonFailedJobs, ({status}) => JOB_STATES_IN_INTEREST_ORDER.indexOf(status))
21
- .slice(0, Math.max(0, maxNonFailedJobsVisible - failedJobs.length))
22
- ),
23
- jobs
24
- )
25
-
26
- const hiddenJobs = jobs.filter(job => filteredJobs.indexOf(job) === -1)
27
- const hiddenCountsByStatus = _.mapValues(
28
- _.groupBy(hiddenJobs, 'status'),
29
- jobsForStatus => jobsForStatus.length
30
- )
31
-
32
- const hiddenJobsText = _(hiddenCountsByStatus)
33
- .toPairs()
34
- .orderBy(([status]) => status)
35
- .value()
36
- .map(([status, count]) => `${count}${NON_BREAKING_SPACE}${status}`)
37
- .join(', ')
38
-
39
- return <ol className="jobs">
40
- {filteredJobs.map(job => <JobElement job={job} key={job.id}/>)}
41
- {
42
- hiddenJobs.length > 0 ? <li className="hidden-jobs">+&nbsp;{hiddenJobsText}</li> : null
43
- }
44
- </ol>
45
- }
46
-
47
- function JobElement({job}: {job: Job}) {
48
- return <li className={job.status}>
49
- <a href={job.url} target="_blank" rel="noopener noreferrer">{job.name}</a>
50
- {!job.url && job.name}
51
- </li>
52
- }
53
-
54
- function sortByOriginalOrder(filteredJobs: Job[], jobs: Job[]) {
55
- return _.orderBy(filteredJobs, (job: Job) => jobs.indexOf(job))
56
- }
@@ -1,51 +0,0 @@
1
- import _ from 'lodash'
2
- import {Info} from './info'
3
- import type {Project} from './gitlab-types'
4
- import React from 'react'
5
- import {Stages} from './stages'
6
-
7
- export function Projects({columns, now, projects, projectsOrder, screen, zoom}: {columns: number, now: number, projects: Project[], projectsOrder: string[], screen: {id: number, total: number}, zoom: number}): JSX.Element {
8
- return <ol className="projects" style={zoomStyle(zoom)}>
9
- {_.sortBy(projects, projectsOrder)
10
- .filter(forScreen(screen, projects.length))
11
- .map(project => <ProjectElement now={now} columns={columns} project={project} key={project.id}/>)
12
- }
13
- </ol>
14
- }
15
-
16
- function ProjectElement({columns, now, project}: {columns: number, now: number, project: Project}) {
17
- const [pipeline] = project.pipelines
18
-
19
- return <li className={`project ${project.status}`} style={style(columns)}>
20
- <h2>
21
- {project.url && <a href={`${project.url}/pipelines`} target="_blank" rel="noopener noreferrer">{project.name}</a>}
22
- {!project.url && project.name}
23
- </h2>
24
- <Stages stages={pipeline.stages} maxNonFailedJobsVisible={project.maxNonFailedJobsVisible}/>
25
- <Info now={now} pipeline={pipeline}/>
26
- </li>
27
- }
28
-
29
- function forScreen(screen: {id: number, total: number}, projectsCount: number) {
30
- const perScreen = Math.ceil(projectsCount / screen.total)
31
- const first = perScreen * (screen.id - 1)
32
- const last = perScreen * screen.id
33
- return (_project: Project, projectIndex: number) => projectIndex >= first && projectIndex < last
34
- }
35
-
36
- function zoomStyle(zoom: number) {
37
- const widthPercentage = Math.round(100 / zoom)
38
- return {
39
- transform: `scale(${zoom})`,
40
- width: `${widthPercentage}vmax`
41
- }
42
- }
43
-
44
- function style(columns: number) {
45
- const marginPx = 12
46
- const widthPercentage = Math.floor(100 / columns)
47
- return {
48
- margin: `${marginPx}px`,
49
- width: `calc(${widthPercentage}% - ${2 * marginPx}px)`
50
- }
51
- }
@@ -1,45 +0,0 @@
1
- import {formatDistance} from 'date-fns'
2
- import type {Stage} from './gitlab-types'
3
-
4
- export function renderTimestamp(stages: Stage[], now: number): string {
5
- const timestamps = getTimestamps(stages)
6
-
7
- if (timestamps.length === 0) {
8
- return 'Pending...'
9
- }
10
-
11
- const finished = timestamps
12
- .map(t => t.finishedAt)
13
- .filter((t): t is number => t !== null)
14
- const inProgress = timestamps.length > finished.length
15
- if (inProgress) {
16
- const [timestamp] = timestamps.sort((a, b) => a.startedAt - b.startedAt)
17
- return renderDistance('Started', timestamp.startedAt, now)
18
- }
19
-
20
- const [latestFinishedAt] = finished.sort((a, b) => b - a)
21
- return renderDistance('Finished', latestFinishedAt, now)
22
- }
23
-
24
- function getTimestamps(stages: Stage[]): {startedAt: number, finishedAt: number | null}[] {
25
- return stages
26
- .flatMap(s => s.jobs)
27
- .map(job => {
28
- const startedAt = job.startedAt ? new Date(job.startedAt).valueOf() : null
29
- const finishedAt = job.finishedAt ? new Date(job.finishedAt).valueOf() : null
30
- return {
31
- startedAt,
32
- finishedAt
33
- }
34
- })
35
- .filter((t): t is {startedAt: number, finishedAt: number | null} => t.startedAt !== null)
36
- }
37
-
38
- function renderDistance(predicate: string, timestamp: number, now: number) {
39
- const distance = formatDate(timestamp, now)
40
- return `${predicate} ${distance} ago`
41
- }
42
-
43
- function formatDate(timestamp: number, now: number) {
44
- return formatDistance(new Date(timestamp), new Date(now))
45
- }
@@ -1,18 +0,0 @@
1
- import {Jobs} from './jobs'
2
- import React from 'react'
3
- import type {Stage} from './gitlab-types'
4
-
5
- export function Stages({stages, maxNonFailedJobsVisible}: {stages: Stage[], maxNonFailedJobsVisible: number}): JSX.Element {
6
- return <ol className="stages">
7
- {stages.map(stage =>
8
- <StageElement stage={stage} maxNonFailedJobsVisible={maxNonFailedJobsVisible} key={stage.name}/>
9
- )}
10
- </ol>
11
- }
12
-
13
- function StageElement({stage, maxNonFailedJobsVisible}: {stage: Stage, maxNonFailedJobsVisible: number}) {
14
- return <li className="stage">
15
- <div className="name">{stage.name}</div>
16
- <Jobs jobs={stage.jobs} maxNonFailedJobsVisible={maxNonFailedJobsVisible}/>
17
- </li>
18
- }
package/src/dev-assets.js DELETED
@@ -1,10 +0,0 @@
1
- import config from '../webpack.dev.js'
2
- import webpack from 'webpack'
3
- import webpackDevMiddleware from 'webpack-dev-middleware'
4
- import webpackHotMiddleware from 'webpack-hot-middleware'
5
-
6
- export function bindDevAssets(app) {
7
- const compiler = webpack(config)
8
- app.use(webpackDevMiddleware(compiler))
9
- app.use(webpackHotMiddleware(compiler))
10
- }
@@ -1,75 +0,0 @@
1
- import * as clientMock from './../../src/gitlab/client'
2
- import {expect} from 'chai'
3
- import {fetchProjects} from './../../src/gitlab/projects'
4
- import sinon from 'sinon'
5
-
6
- describe("projects", () => {
7
- const response = {
8
- data: [
9
- {
10
- path_with_namespace: "group1/pro",
11
- jobs_enabled: true
12
- },
13
- {
14
- path_with_namespace: "group1/pro-other",
15
- jobs_enabled: true
16
- },
17
- {
18
- path_with_namespace: "group2/something",
19
- jobs_enabled: true
20
- },
21
- {
22
- path_with_namespace: "group3/no-ci-pipelines",
23
- jobs_enabled: false
24
- }
25
- ],
26
- headers: {}
27
- }
28
-
29
- before(() => {
30
- sinon.stub(clientMock, 'gitlabRequest').callsFake(() => {
31
- return new Promise((resolve) => {
32
- resolve(response)
33
- })
34
- })
35
- })
36
-
37
- after(() => {
38
- sinon.resetBehavior()
39
- })
40
-
41
- it('should return only included projects', async () => {
42
- const gitlab = {
43
- projects: {
44
- include: '.*/pro.*'
45
- }
46
- }
47
- const projects = await fetchProjects(gitlab)
48
- expect(projects.length).to.equal(2)
49
- expect(projects[0].name).to.equal('group1/pro')
50
- expect(projects[1].name).to.equal('group1/pro-other')
51
- })
52
-
53
- it('should not return excluded projects', async () => {
54
- const gitlab = {
55
- projects: {
56
- exclude: '.*/pro.*'
57
- }
58
- }
59
- const projects = await fetchProjects(gitlab)
60
- expect(projects.length).to.equal(1)
61
- expect(projects[0].name).to.equal('group2/something')
62
- })
63
-
64
- it('should not return excluded and return only included', async () => {
65
- const gitlab = {
66
- projects: {
67
- include: '.*/pro.*',
68
- exclude: '.*/pro-other.*'
69
- }
70
- }
71
- const projects = await fetchProjects(gitlab)
72
- expect(projects.length).to.equal(1)
73
- expect(projects[0].name).to.equal('group1/pro')
74
- })
75
- })