From 5931f5424627f0fc67c6049f5c8f2cfa88193978 Mon Sep 17 00:00:00 2001 From: Armen Zambrano G Date: Fri, 7 Dec 2018 11:55:11 -0500 Subject: [PATCH] Show count of untriaged bugs for each component --- package.json | 1 + .../BugzillaComponentSummary/index.jsx | 55 ++++++++++++++----- src/utils/bugzilla/getLinkToComponent.js | 8 +++ src/utils/bugzilla/getUntriagedBugsCount.js | 23 ++++++++ src/utils/bugzilla/settings.js | 5 ++ src/utils/bugzilla/untriagedParameters.js | 11 ++++ src/utils/fetchJson.js | 13 +++++ src/utils/getBugzillaComponentLink.js | 7 --- src/utils/getBugzillaComponents.js | 8 --- yarn.lock | 13 +++++ 10 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 src/utils/bugzilla/getLinkToComponent.js create mode 100644 src/utils/bugzilla/getUntriagedBugsCount.js create mode 100644 src/utils/bugzilla/settings.js create mode 100644 src/utils/bugzilla/untriagedParameters.js create mode 100644 src/utils/fetchJson.js delete mode 100644 src/utils/getBugzillaComponentLink.js delete mode 100644 src/utils/getBugzillaComponents.js diff --git a/package.json b/package.json index 4a454de..a424051 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@material-ui/icons": "^3.0.1", "@mozilla-frontend-infra/components": "^2.0.0", "prop-types": "^15", + "query-string": "^6.2.0", "react": "^16", "react-dom": "^16", "react-hot-loader": "^4", diff --git a/src/containers/BugzillaComponentSummary/index.jsx b/src/containers/BugzillaComponentSummary/index.jsx index cd9a67c..6318cfb 100644 --- a/src/containers/BugzillaComponentSummary/index.jsx +++ b/src/containers/BugzillaComponentSummary/index.jsx @@ -2,7 +2,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import OpenInNew from '@material-ui/icons/OpenInNew'; import { withStyles } from '@material-ui/core/styles'; -import getBugzillaComponentLink from '../../utils/getBugzillaComponentLink'; +import getLinkToComponent from '../../utils/bugzilla/getLinkToComponent'; +import getUntriagedBugsCount from '../../utils/bugzilla/getUntriagedBugsCount'; const styles = theme => ({ root: { @@ -11,22 +12,48 @@ const styles = theme => ({ icon: { margin: 0, fontSize: '1rem', + verticalAlign: 'text-top', }, }); -const BugzillaComponentSummary = ({ classes, product, component }) => ( -
- {`${product}::${component}`} - - - -
-); +class BugzillaComponentSummary extends React.Component { + state = { + untriaged: undefined, + }; -BugzillaComponentSummary.propTypes = { - classes: PropTypes.shape({}).isRequired, - product: PropTypes.string.isRequired, - component: PropTypes.string.isRequired, -}; + static propTypes = { + classes: PropTypes.shape({}).isRequired, + product: PropTypes.string.isRequired, + component: PropTypes.string.isRequired, + }; + + async componentDidMount() { + this.fetchData(this.props); + } + + async fetchData({ product, component }) { + const untriaged = await getUntriagedBugsCount(product, component); + this.setState({ untriaged }); + } + + render() { + const { classes, product, component } = this.props; + const { untriaged } = this.state; + return ( +
+ {`${product}::${component}`} + + + + {!!untriaged && {untriaged}} +
+ ); + } +} export default withStyles(styles)(BugzillaComponentSummary); diff --git a/src/utils/bugzilla/getLinkToComponent.js b/src/utils/bugzilla/getLinkToComponent.js new file mode 100644 index 0000000..dc9e89c --- /dev/null +++ b/src/utils/bugzilla/getLinkToComponent.js @@ -0,0 +1,8 @@ +import { stringify } from 'query-string'; +import settings from './settings'; +import untriagedParameters from './untriagedParameters'; + +const getBugzillaComponentLink = (product, component) => ( + `${settings.BZ_HOST}/buglist.cgi?${stringify({ product, component, ...untriagedParameters() })}`); + +export default getBugzillaComponentLink; diff --git a/src/utils/bugzilla/getUntriagedBugsCount.js b/src/utils/bugzilla/getUntriagedBugsCount.js new file mode 100644 index 0000000..219157c --- /dev/null +++ b/src/utils/bugzilla/getUntriagedBugsCount.js @@ -0,0 +1,23 @@ +import { stringify } from 'query-string'; +import untriagedParameters from './untriagedParameters'; +import fetchJson from '../fetchJson'; +import settings from './settings'; + +const queryBugzilla = async queryParameters => ( + fetchJson(`${settings.BZ_HOST}/rest/bug?${queryParameters}`)); + +const getUntriagedBugsCount = async (product, component) => { + // eslint-disable-next-line camelcase + const { bug_count = 0 } = await queryBugzilla( + stringify({ + product, + component, + ...untriagedParameters(), + count_only: 1, // This only returns the bug count + }), + ); + // eslint-disable-next-line camelcase + return bug_count; +}; + +export default getUntriagedBugsCount; diff --git a/src/utils/bugzilla/settings.js b/src/utils/bugzilla/settings.js new file mode 100644 index 0000000..6dceedb --- /dev/null +++ b/src/utils/bugzilla/settings.js @@ -0,0 +1,5 @@ +const settings = { + BZ_HOST: 'https://bugzilla.mozilla.org', +}; + +export default settings; diff --git a/src/utils/bugzilla/untriagedParameters.js b/src/utils/bugzilla/untriagedParameters.js new file mode 100644 index 0000000..931c55b --- /dev/null +++ b/src/utils/bugzilla/untriagedParameters.js @@ -0,0 +1,11 @@ +/* eslint-disable indent */ +/* eslint-disable object-property-newline */ +/* eslint-disable no-multi-spaces */ +const untriagedParameters = () => ({ + f1: 'bug_severity', o1: 'notequals', v1: 'enhancement', + f2: 'keywords', o2: 'notsubstring', v2: 'meta', + f3: 'resolution', o3: 'isempty', + limit: 0, +}); + +export default untriagedParameters; diff --git a/src/utils/fetchJson.js b/src/utils/fetchJson.js new file mode 100644 index 0000000..d5351b6 --- /dev/null +++ b/src/utils/fetchJson.js @@ -0,0 +1,13 @@ +const jsonHeaders = { + Accept: 'application/json', +}; + +const fetchJson = async (url) => { + const response = await fetch(url, jsonHeaders); + if (!response) { + return null; + } + return response.json(); +}; + +export default fetchJson; diff --git a/src/utils/getBugzillaComponentLink.js b/src/utils/getBugzillaComponentLink.js deleted file mode 100644 index 2caed32..0000000 --- a/src/utils/getBugzillaComponentLink.js +++ /dev/null @@ -1,7 +0,0 @@ -const getBugzillaComponentLink = (product, component) => ( - 'https://bugzilla.mozilla.org/buglist.cgi?f1=bug_severity&o1=notequals&v1=enhancement' - + `&f2=keywords&o2=notsubstring&v2=meta&f3=product&o3=equals&v3=${product}&f4=component` - + `&o4=equals&v4=${component}&f5=resolution&o5=isempty&limit=0` -); - -export default getBugzillaComponentLink; diff --git a/src/utils/getBugzillaComponents.js b/src/utils/getBugzillaComponents.js deleted file mode 100644 index 6d4c340..0000000 --- a/src/utils/getBugzillaComponents.js +++ /dev/null @@ -1,8 +0,0 @@ -const getBugzillaComponents = async () => { - const { products } = await (await fetch('https://bugzilla.mozilla.org/rest/product' - + '?type=accessible&include_fields=name&include_fields=components' - + '&exclude_fields=components.flag_types&exclude_fields=components.description')).json(); - return products; -}; - -export default getBugzillaComponents; diff --git a/yarn.lock b/yarn.lock index b613596..4707e08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6939,6 +6939,14 @@ qs@6.5.2, qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== +query-string@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.2.0.tgz#468edeb542b7e0538f9f9b1aeb26f034f19c86e1" + integrity sha512-5wupExkIt8RYL4h/FE+WTg3JHk62e6fFPWtAZA9J5IWK1PfTfKkMS93HBUHcFpeYi9KsY5pFbh+ldvEyaz5MyA== + dependencies: + decode-uri-component "^0.2.0" + strict-uri-encode "^2.0.0" + querystring-es3@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" @@ -8041,6 +8049,11 @@ stream-shift@^1.0.0: resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952" integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI= +strict-uri-encode@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" + integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY= + string-argv@^0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.0.2.tgz#dac30408690c21f3c3630a3ff3a05877bdcbd736"