diff --git a/plugins/gatsby-source-jenkinsplugins/__mocks__/plugin-health-score.json b/plugins/gatsby-source-jenkinsplugins/__mocks__/plugin-health-score.json new file mode 100644 index 000000000..2e3e4e739 --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/__mocks__/plugin-health-score.json @@ -0,0 +1,22 @@ +{ + "aws-java-sdk-sns": { + "value": 96, + "version": "1.12.406-370.v8f993c987059", + "details": [ + { + "key": "update-center-plugin-publication", + "value": 1, + "coefficient": 1 + }, + { "key": "security", "value": 1, "coefficient": 1 }, + { + "key": "repository-configuration", + "value": 0.7, + "coefficient": 0.5 + }, + { "key": "adoption", "value": 1, "coefficient": 0.8 }, + { "key": "deprecation", "value": 1, "coefficient": 0.8 } + ], + "timestamp": "2023-03-24T15:15:33.022244Z" + } +} diff --git a/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap b/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap index e2c3d7f8a..b74fad135 100644 --- a/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap +++ b/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap @@ -224,3 +224,47 @@ Array [ }, ] `; + +exports[`utils get plugin healthScore data 1`] = ` +Array [ + Object { + "children": Array [], + "details": Array [ + Object { + "coefficient": 1, + "key": "update-center-plugin-publication", + "value": 1, + }, + Object { + "coefficient": 1, + "key": "security", + "value": 1, + }, + Object { + "coefficient": 0.5, + "key": "repository-configuration", + "value": 0.7, + }, + Object { + "coefficient": 0.8, + "key": "adoption", + "value": 1, + }, + Object { + "coefficient": 0.8, + "key": "deprecation", + "value": 1, + }, + ], + "id": "aws-java-sdk-sns", + "internal": Object { + "contentDigest": "f789c60332b91b320525aea3639a7c73", + "type": "JenkinsPluginHealthScore", + }, + "parent": null, + "timestamp": "2023-03-24T15:15:33.022244Z", + "value": 96, + "version": "1.12.406-370.v8f993c987059", + }, +] +`; diff --git a/plugins/gatsby-source-jenkinsplugins/gatsby-node.js b/plugins/gatsby-source-jenkinsplugins/gatsby-node.js index e35efd273..dba58862b 100644 --- a/plugins/gatsby-source-jenkinsplugins/gatsby-node.js +++ b/plugins/gatsby-source-jenkinsplugins/gatsby-node.js @@ -2,6 +2,7 @@ const { fetchSiteInfo, fetchPluginData, fetchPluginVersions, + fetchPluginHealthScore, processCategoryData, fetchLabelData, fetchStats, @@ -21,6 +22,7 @@ exports.sourceNodes = async ( processCategoryData({createNode, createNodeField, createContentDigest, createNodeId, createRemoteFileNode, reporter}), fetchLabelData({createNode, createNodeField, createContentDigest, createNodeId, createRemoteFileNode, reporter}), fetchPluginVersions({createNode, createNodeField, createContentDigest, createNodeId, createRemoteFileNode, reporter, firstReleases}), + fetchPluginHealthScore({createNode, createNodeField, createContentDigest, createNodeId, createRemoteFileNode, reporter}), ]).then(() => fetchPluginData({createNode, createNodeField, createContentDigest, createNodeId, createRemoteFileNode, reporter, firstReleases, stats})); } catch (err) { reporter.panic( @@ -36,6 +38,7 @@ exports.createSchemaCustomization = ({actions}) => { type JenkinsPlugin implements Node { wiki: JenkinsPluginWiki @link(from: "name", by: "name") releases: [JenkinsPluginVersion] @link(from: "name", by: "name") + healthScore: JenkinsPluginHealthScore @link(from: "name", by: "id") buildDate: Date @dateformat previousTimestamp: Date @dateformat releaseTimestamp: Date @dateformat diff --git a/plugins/gatsby-source-jenkinsplugins/utils.js b/plugins/gatsby-source-jenkinsplugins/utils.js index 427753792..10d9bdcf7 100644 --- a/plugins/gatsby-source-jenkinsplugins/utils.js +++ b/plugins/gatsby-source-jenkinsplugins/utils.js @@ -498,12 +498,37 @@ const fetchPluginVersions = async ({createNode, reporter, firstReleases}) => { sectionActivity.end(); }; +const fetchPluginHealthScore = async ({createNode, reporter}) => { + const sectionActivity = reporter.activityTimer('fetch plugin health score'); + sectionActivity.start(); + const url = 'https://plugin-health.jenkins.io/api/scores'; + const json = await requestGET({url, reporter}); + for (const pluginName of Object.keys(json)) { + const data = json[pluginName]; + createNode({ + ...data, + id: pluginName, + parent: null, + children: [], + internal: { + type: 'JenkinsPluginHealthScore', + contentDigest: crypto + .createHash('md5') + .update(`pluginHealthScore_${pluginName}`) + .digest('hex') + } + }); + } + sectionActivity.end(); +}; + module.exports = { fetchSiteInfo, fetchLabelData, processCategoryData, fetchPluginData, fetchPluginVersions, + fetchPluginHealthScore, fixGitHubUrl, fetchStats, getPluginContent, diff --git a/plugins/gatsby-source-jenkinsplugins/utils.test.js b/plugins/gatsby-source-jenkinsplugins/utils.test.js index a9a7836ca..5f8072033 100644 --- a/plugins/gatsby-source-jenkinsplugins/utils.test.js +++ b/plugins/gatsby-source-jenkinsplugins/utils.test.js @@ -94,4 +94,13 @@ describe('utils', () => { await utils.fetchPluginData({createNode, createNodeId, createContentDigest, reporter: _reporter, firstReleases, labelToCategory, stats}); expect(createNode.mock.calls.filter(call => call[0].name === 'ios-device-connector').map(args => args[0])).toMatchSnapshot(); }); + it('get plugin healthScore data', async () => { + nock('https://plugin-health.jenkins.io') + .get('/api/scores') + .reply(200, JSON.parse(await readText('plugin-health-score.json'))); + const createNode = jest.fn().mockResolvedValue(); + + await utils.fetchPluginHealthScore({createNode, reporter: _reporter}); + expect(createNode.mock.calls.filter(call => call[0].id === 'aws-java-sdk-sns').map(args => args[0])).toMatchSnapshot(); + }); }); diff --git a/plugins/plugin-site/src/components/Plugin.jsx b/plugins/plugin-site/src/components/Plugin.jsx index 3cac1ab70..bc6b357ef 100644 --- a/plugins/plugin-site/src/components/Plugin.jsx +++ b/plugins/plugin-site/src/components/Plugin.jsx @@ -1,13 +1,13 @@ import PropTypes from 'prop-types'; import React from 'react'; - import {navigate} from 'gatsby'; - import {cleanTitle} from '../commons/helper'; import Icon from '../components/Icon'; import PluginLabels from '../components/PluginLabels'; import PluginLastReleased from '../components/PluginLastReleased'; import PluginDevelopers from '../components/PluginDevelopers'; +import PluginHealthScore from '../components/PluginHealthScore'; + function Developers({developers}) { return ( @@ -24,7 +24,8 @@ function Developers({developers}) { Developers.propTypes = PluginDevelopers.propTypes; -function Plugin({plugin: {name, title, stats, labels, excerpt, developers, buildDate, releaseTimestamp}}) { +function Plugin({plugin: {name, title, stats, labels, excerpt, developers, buildDate, releaseTimestamp, healthScore}}) { + return (