Skip to content

Commit

Permalink
Merge 1fefcc4 into 3a2bc32
Browse files Browse the repository at this point in the history
  • Loading branch information
mpereira2097 committed Jul 18, 2019
2 parents 3a2bc32 + 1fefcc4 commit e34e8e9
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 19 deletions.
49 changes: 49 additions & 0 deletions README.md
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
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
110 changes: 110 additions & 0 deletions src/components/MergeRequestsStatus.js
@@ -0,0 +1,110 @@
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.number.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: 0,
}

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

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

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
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,
}
38 changes: 19 additions & 19 deletions test/components/__snapshots__/Branches.test.js.snap
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 @@ -1223,7 +1223,7 @@ exports[`should render as expected 1`] = `
/>
</svg>
 
a year ago
2 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
a year ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1579,7 +1579,7 @@ exports[`should render as expected 1`] = `
/>
</svg>
 
6 months ago
a year ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1668,7 +1668,7 @@ exports[`should render as expected 1`] = `
/>
</svg>
 
6 months ago
a year ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1757,7 +1757,7 @@ exports[`should render as expected 1`] = `
/>
</svg>
 
6 months ago
a year ago
</span>
</div>
</div>
Expand Down Expand Up @@ -1846,7 +1846,7 @@ exports[`should render as expected 1`] = `
/>
</svg>
 
5 months ago
a year ago
</span>
</div>
</div>
Expand Down

0 comments on commit e34e8e9

Please sign in to comment.