Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,55 @@ key | required | default | description
y: 0
```

## GitLab merge requests status

> Show GitLab project's merge requests status

### parameters

key | required | default | description
------------|----------|-----------------------|----------------
`project` | yes | *n/a* | *ID or NAMESPACE/PROJECT_NAME of a project*
`status` | no | 'opened' |
`thresholds`| no | - threshold: 0
textColor: 'text'
bgColor: 'success'
message: 'good job!'
- threshold: 3
textColor: 'text'
bgColor: 'warning'
message: 'you should consider reviewing'
- threshold: 5
textColor: 'text'
bgColor: 'failure'
message: 'merge requests overflow'

### usage

``` yaml
- extension: gitlab
widget: MergeRequestsStatus
project: gitlab-org/gitlab-ce
columns: 1
status: 'opened'
thresholds:
- threshold: 0
textColor: 'text'
bgColor: 'success'
message: 'good job!'
- threshold: 3
textColor: 'text'
bgColor: 'warning'
message: 'you should consider reviewing'
- threshold: 5
textColor: 'text'
bgColor: 'failure'
message: 'merge requests overflow'
rows: 1
x: 0
y: 0
```


[license-image]: https://img.shields.io/github/license/plouc/mozaik-ext-gitlab.svg?style=flat-square
[license-url]: https://github.com/plouc/mozaik-ext-gitlab/blob/master/LICENSE.md
Expand Down
3 changes: 3 additions & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ module.exports = mozaik => {
projectMergeRequests({ project, query = {} }) {
return gitlab.getProjectMergeRequests(project, query)
},
projectMergeRequestsStatus({ project, query = {} }) {
return gitlab.getProjectMergeRequests(project, query)
},
projectLabels({ project }) {
return Promise.all([gitlab.getProject(project), gitlab.getProjectLabels(project)]).then(
([project, labels]) => ({
Expand Down
112 changes: 112 additions & 0 deletions src/components/MergeRequestsStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Widget, WidgetHeader, WidgetBody } from '@mozaik/ui'

export default class MergeRequestsStatus extends Component {
static propTypes = {
project: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
status: PropTypes.string,
thresholds: PropTypes.arrayOf(
PropTypes.shape({
threshold: PropTypes.number.isRequired,
textColor: PropTypes.string.isRequired,
bgColor: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
})
).isRequired,
apiData: PropTypes.object.isRequired,
apiError: PropTypes.object,
theme: PropTypes.object.isRequired,
}

static defaultProps = {
thresholds: [
{
threshold: 0,
textColor: 'text',
bgColor: 'success',
message: 'good job!',
},
{
threshold: 3,
textColor: 'text',
bgColor: 'warning',
message: 'you should consider reviewing',
},
{
threshold: 5,
textColor: 'text',
bgColor: 'failure',
message: 'merge requests overflow',
},
],
apiData: { items: [] },
}

static getApiRequest({ project, status = 'opened' }) {
return {
id: `gitlab.projectMergeRequestsStatus.${project}.${status}`,
params: {
project,
query: {
state: status,
},
},
}
}

render() {
const { thresholds, apiData, theme } = this.props

const mergeRequestCount = apiData.items ? apiData.items.length : 0

let currentThreshold
let count = 0
thresholds.map((threshold, index) => {
if (mergeRequestCount >= threshold.threshold) {
count = index
}
return null
})
currentThreshold = thresholds[count]

const backgroundColor = theme.colors[currentThreshold.bgColor]
? theme.colors[currentThreshold.bgColor]
: ''
const fontColor = theme.colors[currentThreshold.textColor]
? theme.colors[currentThreshold.textColor]
: theme.colors.text

return (
<Widget>
<WidgetHeader title="Pending Merge Requests" icon="dashboard" />
<WidgetBody
style={{
background: backgroundColor,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: fontColor,
fontWeight: 'bolder',
}}
>
<div>
<div
style={{
fontSize: '3rem',
lineHeight: '3.5rem',
width: '100%',
textAlign: 'center',
}}
>
{parseInt(mergeRequestCount, 10)}
</div>
<div style={{ width: '100%', textAlign: 'center' }}>
{currentThreshold.message}
</div>
</div>
</WidgetBody>
</Widget>
)
}
}
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Branches from './Branches'
import ProjectActivity from './activity/ProjectActivity'
import ProjectMilestones from './ProjectMilestones'
import LatestProjectPipeline from './pipelines/LatestProjectPipeline'
import MergeRequestsStatus from './MergeRequestsStatus'
import * as labels from './labels'

export default {
Expand All @@ -19,5 +20,6 @@ export default {
ProjectActivity,
ProjectMilestones,
LatestProjectPipeline,
MergeRequestsStatus,
...labels,
}
40 changes: 20 additions & 20 deletions test/components/__snapshots__/Branches.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

3 years ago
4 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -244,7 +244,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

3 years ago
4 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -333,7 +333,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -422,7 +422,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -511,7 +511,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

a year ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -600,7 +600,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

a year ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -689,7 +689,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -778,7 +778,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -867,7 +867,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -956,7 +956,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1045,7 +1045,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1134,7 +1134,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

2 years ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1223,7 +1223,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

a year ago
3 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1312,7 +1312,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

a year ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1401,7 +1401,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

10 months ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1490,7 +1490,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

6 months ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1579,7 +1579,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

6 months ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1668,7 +1668,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

6 months ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1757,7 +1757,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

6 months ago
2 years ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1846,7 +1846,7 @@ exports[`should render as expected 1`] = `
/>
</svg>

5 months ago
2 years ago
</span>
</div>
</div>
Expand Down