Skip to content

Commit

Permalink
Use issue tracker data from update center
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynek committed Jun 20, 2021
1 parent 4f847c6 commit 2809478
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

exports[`Utils Get plugin data for a wiki based plugin 1`] = `
Object {
"buildDate": "2012-10-10",
"buildDate": "Oct 10, 2012",
"categories": Array [
"languagesPlatforms",
"buildManagement",
],
"children": Array [],
"defaultBranch": "master",
"dependencies": Array [
Object {
"implied": true,
Expand Down Expand Up @@ -109,7 +110,7 @@ Object {
},
],
"excerpt": "Talks to iOS devices connected to slaves and do stuff.",
"firstRelease": "2012-10-07T18:59:35.16Z",
"firstRelease": "1970-01-01T00:00:00.000Z",
"gav": "org.jenkins-ci.plugins:ios-device-connector:1.2",
"hasBomEntry": false,
"hasPipelineSteps": false,
Expand All @@ -118,32 +119,30 @@ Object {
"contentDigest": "7da41342fb756c851d4b5a9b6b6f9f3e",
"type": "JenkinsPlugin",
},
"issueTrackers": Array [
Object {
"reportUrl": "https://www.jenkins.io/participate/report-issue/redirect/#17020",
"type": "jira",
"viewUrl": "https://issues.jenkins.io/issues/?jql=component=17020",
},
],
"labels": Array [
"builder",
"ios",
],
"maintainers": Array [
Object {
"email": null,
"id": "kohsuke",
"name": null,
},
],
"maintainers": Array [],
"name": "ios-device-connector",
"parent": null,
"previousTimestamp": "2012-10-08T20:04:52.00Z",
"popularity": 275,
"previousTimestamp": "2012-10-08T20:04:36.00Z",
"previousVersion": "1.1",
"releaseTimestamp": "2012-10-10T17:27:58.00Z",
"releaseTimestamp": "2012-10-10T17:27:42.00Z",
"requiredCore": "1.466",
"scm": Object {
"inLatestRelease": null,
"issues": null,
"link": "https://github.com/jenkinsci/ios-device-connector-plugin",
"pullRequests": null,
"sinceLatestRelease": null,
},
"securityWarnings": null,
"scm": "https://github.com/jenkinsci/ios-device-connector-plugin",
"securityWarnings": Array [],
"sha1": "B2z2wTyA8l5uwz9HqD+xhG9Hjns=",
"sha256": "Tray3+tyfE6xoTu1Rge9+INkcj5y7Bgw7nPm//saiYw=",
"size": 1548862,
"stats": Object {
"currentInstalls": 365,
"installations": Array [
Expand Down Expand Up @@ -869,7 +868,7 @@ Object {
"trend": -15,
},
"title": "iOS Device connector",
"url": "http://updates.jenkins-ci.org/download/plugins/ios-device-connector/1.2/ios-device-connector.hpi",
"url": "https://updates.jenkins.io/download/plugins/ios-device-connector/1.2/ios-device-connector.hpi",
"version": "1.2",
"wiki": Object {
"content": "
Expand Down
55 changes: 3 additions & 52 deletions plugins/gatsby-source-jenkinsplugins/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
/*
plugins: `
firstRelease: Date
buildDate: Date
categories: {
id: String!
}
dependencies: {
name: String
title: String
optional: Boolean
version: String
implied: Boolean
}
maintainers: {
id: String
name: String
}
excerpt: String
gav: String
labels: {
id: String!
}
name: String
previousTimestamp: Date
previousVersion: String
releaseTimestamp: Date
requiredCore: String
scm: {
issues: String
link: String
inLatestRelease: String
sinceLatestRelease: String
pullRequest: String
}
sha1: String
// stats:
title: String
url: String
version: String
// securityWarnings:
wiki: {
content: String
url: String
}
`
*/

const {
fetchSiteInfo,
fetchPluginData,
Expand All @@ -54,21 +6,20 @@ const {
fetchLabelData,
} = require('./utils');


exports.sourceNodes = async (
{actions, reporter},
{ /* options */ } // eslint-disable-line no-empty-pattern
) => {
const {createNode} = actions;

try {
const firstReleases = {};
await Promise.all([
fetchSiteInfo({createNode, reporter}),
fetchPluginData({createNode, reporter}),
fetchCategoryData({createNode, reporter}),
fetchLabelData({createNode, reporter}),
fetchPluginVersions({createNode, reporter}),
]);
fetchPluginVersions({createNode, reporter, firstReleases}),
]).then(() => fetchPluginData({createNode, reporter, firstReleases}));
} catch (err) {
reporter.panic(
`gatsby-source-jenkinsplugin: Failed to parse API call - ${err.stack || err}`
Expand Down
31 changes: 23 additions & 8 deletions plugins/gatsby-source-jenkinsplugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const getPluginContent = async ({plugin, reporter}) => {
});
};

const fetchPluginData = async ({createNode, reporter}) => {
const fetchPluginData = async ({createNode, reporter, firstReleases}) => {
const sectionActivity = reporter.activityTimer('fetch plugins info');
sectionActivity.start();
const promises = [];
Expand All @@ -105,15 +105,28 @@ const fetchPluginData = async ({createNode, reporter}) => {
const pipelinePluginsUrl = 'https://www.jenkins.io/doc/pipeline/steps/contents.json';
const pipelinePluginIds = await requestGET({url: pipelinePluginsUrl, reporter});
const bomDependencies = await fetchBomDependencies(reporter);
const updateUrl = 'https://updates.jenkins.io/update-center.actual.json';
const updateData = await requestGET({url: updateUrl, reporter});
do {
const url = `https://plugins.jenkins.io/api/plugins/?limit=100&page=${page}`;
pluginsContainer = await requestGET({url, reporter});
for (const plugin of pluginsContainer.plugins) {
const pluginName = plugin.name.trim();
names.push(pluginName);
const pluginUC = updateData.plugins[pluginName];
pluginUC.maintainers = pluginUC.developers;
pluginUC.maintainers.forEach(maint => {maint.id = maint.developerId, delete(maint.developerId);});
delete(pluginUC.developers);
promises.push(getPluginContent({plugin, reporter}).then(pluginData => {
const p = createNode({
...pluginData,
...pluginUC,
stats: pluginData.stats,
wiki: pluginData.wiki,
securityWarnings: updateData.warnings.filter(p => p.name == pluginName)
.map(w => {w.active = !!pluginData.version.match(`^${w.versions[0].pattern}$`); return w;}),
dependencies: pluginData.dependencies,
categories: pluginData.categories,
firstRelease: firstReleases[pluginName].toISOString(),
id: pluginName,
hasPipelineSteps: pipelinePluginIds.includes(pluginName),
hasBomEntry: !!bomDependencies.find(artifactId => pluginData.gav.includes(`:${artifactId}:`)),
Expand Down Expand Up @@ -167,7 +180,7 @@ const fetchPluginData = async ({createNode, reporter}) => {
page = pluginsContainer.page + 1;
} while (!page || pluginsContainer.page < pluginsContainer.pages);
await Promise.all(promises);
await fetchSuspendedPlugins({names, createNode, reporter});
await fetchSuspendedPlugins({updateData, names, createNode});
sectionActivity.end();
};

Expand All @@ -183,9 +196,7 @@ const fetchBomDependencies = async (reporter) => {
return [];
};

const fetchSuspendedPlugins = async ({names, createNode, reporter}) => {
const updateUrl = 'https://updates.jenkins.io/update-center.actual.json';
const updateData = await requestGET({url: updateUrl, reporter});
const fetchSuspendedPlugins = async ({updateData, names, createNode}) => {
const suspendedPromises = [];
for (const deprecation of Object.keys(updateData.deprecations)) {
if (!names.includes(deprecation)) {
Expand Down Expand Up @@ -279,7 +290,7 @@ const fetchSiteInfo = async ({createNode, reporter}) => {
};


const fetchPluginVersions = async ({createNode, reporter}) => {
const fetchPluginVersions = async ({createNode, reporter, firstReleases}) => {
const sectionActivity = reporter.activityTimer('fetch plugin versions');
sectionActivity.start();
const url = 'https://updates.jenkins.io/plugin-versions.json';
Expand All @@ -296,9 +307,13 @@ const fetchPluginVersions = async ({createNode, reporter}) => {
url "https://updates.jenkins.io/download/plugins/42crunch-security-audit/2.1/42crunch-security-audit.hpi"
version 2.1
*/
const date = dateFNs.parse(data.buildDate, 'MMMM d, yyyy', new Date(0));
if (!firstReleases[data.name] || firstReleases[data.name].getTime() > date.getTime()) {
firstReleases[data.name] = date;
}
createNode({
...data,
buildDate: dateFNs.parse(data.buildDate, 'MMMM d, yyyy', new Date(0)),
buildDate: date,
id: `${data.name}_${data.version}`,
parent: null,
children: [],
Expand Down
19 changes: 17 additions & 2 deletions plugins/gatsby-source-jenkinsplugins/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ describe('Utils', () => {
it('Get plugin data for a wiki based plugin', async () => {
nock('https://updates.jenkins.io')
.get('/update-center.actual.json')
.reply(200, {deprecations: []});
.reply(200, {deprecations: [], warnings: [], plugins: {
'ios-device-connector': {'buildDate': 'Oct 10, 2012','defaultBranch': 'master','dependencies': [],
'developers': [],'excerpt': 'Talks to iOS devices connected to slaves and do stuff.',
'gav': 'org.jenkins-ci.plugins:ios-device-connector:1.2',
'issueTrackers': [{'reportUrl': 'https://www.jenkins.io/participate/report-issue/redirect/#17020',
'type': 'jira','viewUrl': 'https://issues.jenkins.io/issues/?jql=component=17020'}],
'labels': ['builder','ios'],'name': 'ios-device-connector','popularity': 275,
'previousTimestamp': '2012-10-08T20:04:36.00Z','previousVersion': '1.1',
'releaseTimestamp': '2012-10-10T17:27:42.00Z','requiredCore': '1.466',
'scm': 'https://github.com/jenkinsci/ios-device-connector-plugin',
'sha1': 'B2z2wTyA8l5uwz9HqD+xhG9Hjns=',
'sha256': 'Tray3+tyfE6xoTu1Rge9+INkcj5y7Bgw7nPm//saiYw=','size': 1548862,
'title': 'iOS Device connector','url': 'https://updates.jenkins.io/download/plugins/ios-device-connector/1.2/ios-device-connector.hpi',
'version': '1.2','wiki': 'https://plugins.jenkins.io/ios-device-connector'}
}});
nock('https://www.jenkins.io')
.get('/doc/pipeline/steps/contents.json')
.reply(200, []);
Expand All @@ -53,7 +67,8 @@ describe('Utils', () => {
.replyWithFile(200, path.join(__dirname, '__mocks__', 'wiki.jenkins.io.io-device-connector-plugin.json'), {'Content-Type': 'application/json'});

const createNode = jest.fn().mockResolvedValue();
await utils.fetchPluginData({createNode, reporter: _reporter});
const firstReleases = {'ios-device-connector': new Date(0)};
await utils.fetchPluginData({createNode, reporter: _reporter, firstReleases});
expect(createNode.mock.calls[0][0]).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions src/components/ReportAProblem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import PropTypes from 'prop-types';

function ReportAProblem({reportProblemTitle, reportProblemUrl, reportProblemRelativeSourcePath}) {
const title = `Report a problem with ${reportProblemRelativeSourcePath}`;

const pluginSiteReportUrl = `https://github.com/jenkins-infra/plugin-site/issues/new?labels=bug&template=4-bug.md&title=${reportProblemTitle} page - TODO: Put a summary here&body=Problem with the [${reportProblemTitle}](https://plugins.jenkins.io${reportProblemUrl}) page, [source file](https://github.com/jenkins-infra/plugin-site/tree/master/src/${reportProblemRelativeSourcePath})%0A%0ATODO: Describe the expected and actual behavior here %0A%0A%23%23 Screenshots %0A%0A TODO: Add screenshots if possible %0A%0A%23%23 Possible Solution %0A%0A%3C!-- If you have suggestions on a fix for the bug, please describe it here. --%3E %0A%0AN/A`;
return (
<p className="box">
<a href={`https://github.com/jenkins-infra/plugin-site/issues/new?labels=bug&template=4-bug.md&title=${reportProblemTitle} page - TODO: Put a summary here&body=Problem with the [${reportProblemTitle}](https://plugins.jenkins.io${reportProblemUrl}) page, [source file](https://github.com/jenkins-infra/plugin-site/tree/master/src/${reportProblemRelativeSourcePath})%0A%0ATODO: Describe the expected and actual behavior here %0A%0A%23%23 Screenshots %0A%0A TODO: Add screenshots if possible %0A%0A%23%23 Possible Solution %0A%0A%3C!-- If you have suggestions on a fix for the bug, please describe it here. --%3E %0A%0AN/A`} title={title}>
<a href={reportProblemUrl.startsWith('http') ? reportProblemUrl : pluginSiteReportUrl} title={title}>
Report a problem
</a>
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export const PluginFragment = graphql`
lastVersion
}
}
scm {
link
issueTrackers {
reportUrl
viewUrl
}
scm
hasPipelineSteps
requiredCore
releaseTimestamp
Expand Down
17 changes: 8 additions & 9 deletions src/templates/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function PluginPage({data: {jenkinsPlugin: plugin, reverseDependencies: reverseD
const pluginPage = 'templates/plugin.jsx';

return (
<Layout id="pluginPage" reportProblemRelativeSourcePath={pluginPage} reportProblemUrl={`/${plugin.name}`} reportProblemTitle={plugin.title}>
<Layout id="pluginPage" reportProblemRelativeSourcePath={pluginPage} reportProblemTitle={plugin.title}
reportProblemUrl={plugin.issueTrackers[0] && plugin.issueTrackers[0] ? plugin.issueTrackers[0].reportUrl : `/${plugin.name}`}>
<SEO title={cleanTitle(plugin.title)} description={plugin.excerpt} pathname={`/${plugin.id}`}/>
<div className="title-wrapper">
<h1 className="title">
Expand Down Expand Up @@ -101,7 +102,11 @@ function PluginPage({data: {jenkinsPlugin: plugin, reverseDependencies: reverseD
</div>
<div className="sidebarSection">
<h5>Links</h5>
{plugin.scm && plugin.scm.link && <div className="label-link"><a href={plugin.scm.link}>GitHub</a></div>}
{plugin.scm && <div className="label-link"><a href={plugin.scm}>GitHub</a></div>}
{plugin.issueTrackers && plugin.issueTrackers[0] && <>
<div className="label-link"><a href={plugin.issueTrackers[0].viewUrl}>Open issues</a></div>
<div className="label-link"><a href={plugin.issueTrackers[0].reportUrl}>Report an issue</a></div>
</>}
{plugin.hasPipelineSteps && <div className="label-link"><a href={`https://www.jenkins.io/doc/pipeline/steps/${plugin.name}`}>Pipeline Step Reference</a></div>}
<div className="label-link"><a href={`https://javadoc.jenkins.io/plugin/${plugin.name}`}>Javadoc</a></div>
</div>
Expand Down Expand Up @@ -180,13 +185,7 @@ PluginPage.propTypes = {
})),
name: PropTypes.string.isRequired,
requiredCore: PropTypes.string,
scm: PropTypes.shape({
inLatestRelease: PropTypes.string,
issues: PropTypes.string,
link: PropTypes.string,
pullRequests: PropTypes.string,
sinceLatestRelease: PropTypes.string
}),
scm: PropTypes.string,
securityWarnings: PropTypes.arrayOf(PropTypes.shape({
active: PropTypes.boolean,
id: PropTypes.string,
Expand Down

0 comments on commit 2809478

Please sign in to comment.