From 1e39f757a9962580da7c8bb61b454ba85b64b8d3 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Tue, 14 Jan 2020 21:14:03 -0800 Subject: [PATCH] Switch to pulling wiki content directly since it seems to fairly often fail to pull from api --- .eslintrc.js | 3 +- package.json | 2 + ...ns.io.api.plugin.ios-device-connector.json | 865 +++++++++++++++++ ...jenkins.io.io-device-connector-plugin.json | 1 + .../__snapshots__/utils.test.js.snap | 914 ++++++++++++++++++ .../gatsby-node.js | 137 +-- plugins/gatsby-source-jenkinsplugins/utils.js | 191 ++++ .../utils.test.js | 50 + yarn.lock | 23 + 9 files changed, 2054 insertions(+), 132 deletions(-) create mode 100644 plugins/gatsby-source-jenkinsplugins/__mocks__/plugins.jenkins.io.api.plugin.ios-device-connector.json create mode 100644 plugins/gatsby-source-jenkinsplugins/__mocks__/wiki.jenkins.io.io-device-connector-plugin.json create mode 100644 plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap create mode 100644 plugins/gatsby-source-jenkinsplugins/utils.js create mode 100644 plugins/gatsby-source-jenkinsplugins/utils.test.js diff --git a/.eslintrc.js b/.eslintrc.js index fe8b74b05..5aa915c28 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,8 @@ module.exports = { '__tests__/**/*.js', '__tests__/**/*.jsx', '__mocks__/**/*.js', - '__mocks__/**/*.jsx' + '__mocks__/**/*.jsx', + '**/*.test.js', ], 'plugins': ['jest'], 'rules': {} diff --git a/package.json b/package.json index 00d6c9229..9b7804228 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "reactstrap": "^8.2.0" }, "devDependencies": { + "axios-retry": "^3.1.2", "babel-jest": "^24.9.0", "babel-preset-gatsby": "^0.2.26", "eslint": "^6.7.1", @@ -106,6 +107,7 @@ "jest": "^24.9.0", "jest-junit": "^10.0.0", "lint-staged": "^9.5.0", + "nock": "^11.7.2", "react": "^16.12.0", "react-dom": "^16.12.0", "react-test-renderer": "^16.12.0", diff --git a/plugins/gatsby-source-jenkinsplugins/__mocks__/plugins.jenkins.io.api.plugin.ios-device-connector.json b/plugins/gatsby-source-jenkinsplugins/__mocks__/plugins.jenkins.io.api.plugin.ios-device-connector.json new file mode 100644 index 000000000..502a02765 --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/__mocks__/plugins.jenkins.io.api.plugin.ios-device-connector.json @@ -0,0 +1,865 @@ +{ + "firstRelease": "2012-10-07T18:59:35.16Z", + "buildDate": "2012-10-10", + "categories": [ + "languagesPlatforms", + "buildManagement" + ], + "dependencies": [ + { + "name": "external-monitor-job", + "title": "External Monitor Job Type", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "ldap", + "title": "LDAP", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "pam-auth", + "title": "PAM Authentication", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "mailer", + "title": "Mailer", + "optional": false, + "version": "1.2", + "implied": true + }, + { + "name": "matrix-auth", + "title": "Matrix Authorization Strategy", + "optional": false, + "version": "1.0.2", + "implied": true + }, + { + "name": "windows-slaves", + "title": "WMI Windows Agents", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "antisamy-markup-formatter", + "title": "OWASP Markup Formatter", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "matrix-project", + "title": "Matrix Project", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "junit", + "title": "JUnit", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "bouncycastle-api", + "title": "bouncycastle API", + "optional": false, + "version": "2.16.0", + "implied": true + }, + { + "name": "command-launcher", + "title": "Command Agent Launcher", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "jdk-tool", + "title": "Oracle Java SE Development Kit Installer", + "optional": false, + "version": "1.0", + "implied": true + }, + { + "name": "jaxb", + "title": "JAXB", + "optional": false, + "version": "2.3.0", + "implied": true + }, + { + "name": "trilead-api", + "title": "Trilead API", + "optional": false, + "version": "1.0.4", + "implied": true + } + ], + "maintainers": [ + { + "id": "kohsuke", + "name": null, + "email": null + } + ], + "excerpt": "Talks to iOS devices connected to slaves and do stuff.", + "gav": "org.jenkins-ci.plugins:ios-device-connector:1.2", + "labels": [ + "builder", + "ios" + ], + "name": "ios-device-connector", + "previousTimestamp": "2012-10-08T20:04:52.00Z", + "previousVersion": "1.1", + "releaseTimestamp": "2012-10-10T17:27:58.00Z", + "requiredCore": "1.466", + "scm": { + "issues": null, + "link": "https://github.com/jenkinsci/ios-device-connector-plugin", + "inLatestRelease": null, + "sinceLatestRelease": null, + "pullRequests": null + }, + "sha1": "B2z2wTyA8l5uwz9HqD+xhG9Hjns=", + "stats": { + "installations": [ + { + "timestamp": 1349049600000, + "total": 55 + }, + { + "timestamp": 1351728000000, + "total": 97 + }, + { + "timestamp": 1354320000000, + "total": 123 + }, + { + "timestamp": 1356998400000, + "total": 177 + }, + { + "timestamp": 1359676800000, + "total": 186 + }, + { + "timestamp": 1362096000000, + "total": 192 + }, + { + "timestamp": 1364774400000, + "total": 229 + }, + { + "timestamp": 1367366400000, + "total": 235 + }, + { + "timestamp": 1370044800000, + "total": 256 + }, + { + "timestamp": 1372636800000, + "total": 262 + }, + { + "timestamp": 1375315200000, + "total": 282 + }, + { + "timestamp": 1377993600000, + "total": 295 + }, + { + "timestamp": 1380585600000, + "total": 302 + }, + { + "timestamp": 1383264000000, + "total": 299 + }, + { + "timestamp": 1385856000000, + "total": 300 + }, + { + "timestamp": 1388534400000, + "total": 312 + }, + { + "timestamp": 1391212800000, + "total": 318 + }, + { + "timestamp": 1393632000000, + "total": 330 + }, + { + "timestamp": 1396310400000, + "total": 321 + }, + { + "timestamp": 1398902400000, + "total": 343 + }, + { + "timestamp": 1401580800000, + "total": 337 + }, + { + "timestamp": 1404172800000, + "total": 360 + }, + { + "timestamp": 1406851200000, + "total": 357 + }, + { + "timestamp": 1409529600000, + "total": 371 + }, + { + "timestamp": 1412121600000, + "total": 376 + }, + { + "timestamp": 1414800000000, + "total": 367 + }, + { + "timestamp": 1417392000000, + "total": 356 + }, + { + "timestamp": 1420070400000, + "total": 371 + }, + { + "timestamp": 1422748800000, + "total": 357 + }, + { + "timestamp": 1425168000000, + "total": 398 + }, + { + "timestamp": 1427846400000, + "total": 380 + }, + { + "timestamp": 1430438400000, + "total": 373 + }, + { + "timestamp": 1433116800000, + "total": 397 + }, + { + "timestamp": 1435708800000, + "total": 399 + }, + { + "timestamp": 1438387200000, + "total": 401 + }, + { + "timestamp": 1441065600000, + "total": 403 + }, + { + "timestamp": 1443657600000, + "total": 415 + }, + { + "timestamp": 1446336000000, + "total": 400 + }, + { + "timestamp": 1448928000000, + "total": 414 + }, + { + "timestamp": 1451606400000, + "total": 421 + }, + { + "timestamp": 1454284800000, + "total": 363 + }, + { + "timestamp": 1456790400000, + "total": 360 + }, + { + "timestamp": 1459468800000, + "total": 359 + }, + { + "timestamp": 1462060800000, + "total": 386 + }, + { + "timestamp": 1464739200000, + "total": 390 + }, + { + "timestamp": 1467331200000, + "total": 353 + }, + { + "timestamp": 1470009600000, + "total": 373 + }, + { + "timestamp": 1472688000000, + "total": 385 + }, + { + "timestamp": 1475280000000, + "total": 357 + }, + { + "timestamp": 1477958400000, + "total": 354 + }, + { + "timestamp": 1480550400000, + "total": 356 + }, + { + "timestamp": 1483228800000, + "total": 359 + }, + { + "timestamp": 1485907200000, + "total": 358 + }, + { + "timestamp": 1488326400000, + "total": 374 + }, + { + "timestamp": 1491004800000, + "total": 348 + }, + { + "timestamp": 1493596800000, + "total": 345 + }, + { + "timestamp": 1496275200000, + "total": 352 + }, + { + "timestamp": 1498867200000, + "total": 350 + }, + { + "timestamp": 1501545600000, + "total": 339 + }, + { + "timestamp": 1504224000000, + "total": 370 + }, + { + "timestamp": 1506816000000, + "total": 357 + }, + { + "timestamp": 1509494400000, + "total": 384 + }, + { + "timestamp": 1512086400000, + "total": 361 + }, + { + "timestamp": 1514764800000, + "total": 372 + }, + { + "timestamp": 1517443200000, + "total": 358 + }, + { + "timestamp": 1519862400000, + "total": 370 + }, + { + "timestamp": 1522540800000, + "total": 356 + }, + { + "timestamp": 1525132800000, + "total": 367 + }, + { + "timestamp": 1527811200000, + "total": 367 + }, + { + "timestamp": 1530403200000, + "total": 396 + }, + { + "timestamp": 1533081600000, + "total": 423 + }, + { + "timestamp": 1535760000000, + "total": 410 + }, + { + "timestamp": 1538352000000, + "total": 427 + }, + { + "timestamp": 1541030400000, + "total": 440 + }, + { + "timestamp": 1543640400000, + "total": 429 + }, + { + "timestamp": 1546318800000, + "total": 428 + }, + { + "timestamp": 1548997200000, + "total": 430 + }, + { + "timestamp": 1551416400000, + "total": 473 + }, + { + "timestamp": 1554091200000, + "total": 455 + }, + { + "timestamp": 1556683200000, + "total": 446 + }, + { + "timestamp": 1559361600000, + "total": 417 + }, + { + "timestamp": 1561953600000, + "total": 425 + }, + { + "timestamp": 1564632000000, + "total": 410 + }, + { + "timestamp": 1567310400000, + "total": 409 + }, + { + "timestamp": 1569902400000, + "total": 407 + }, + { + "timestamp": 1572580800000, + "total": 380 + }, + { + "timestamp": 1575176400000, + "total": 365 + } + ], + "installationsPercentage": [ + { + "timestamp": 1349049600000, + "percentage": 0.10514242018734468 + }, + { + "timestamp": 1351728000000, + "percentage": 0.18167175472440208 + }, + { + "timestamp": 1354320000000, + "percentage": 0.2390159538291133 + }, + { + "timestamp": 1356998400000, + "percentage": 0.3111048616725841 + }, + { + "timestamp": 1359676800000, + "percentage": 0.3244148323856699 + }, + { + "timestamp": 1362096000000, + "percentage": 0.3109664253437637 + }, + { + "timestamp": 1364774400000, + "percentage": 0.35684233490198525 + }, + { + "timestamp": 1367366400000, + "percentage": 0.35990504632820275 + }, + { + "timestamp": 1370044800000, + "percentage": 0.38952541805511176 + }, + { + "timestamp": 1372636800000, + "percentage": 0.37967712952496885 + }, + { + "timestamp": 1375315200000, + "percentage": 0.4127090986257665 + }, + { + "timestamp": 1377993600000, + "percentage": 0.4217961366333519 + }, + { + "timestamp": 1380585600000, + "percentage": 0.4070464868653377 + }, + { + "timestamp": 1383264000000, + "percentage": 0.404518703916661 + }, + { + "timestamp": 1385856000000, + "percentage": 0.4160829946880071 + }, + { + "timestamp": 1388534400000, + "percentage": 0.4048898232500195 + }, + { + "timestamp": 1391212800000, + "percentage": 0.4044823770335415 + }, + { + "timestamp": 1393632000000, + "percentage": 0.3987915407854985 + }, + { + "timestamp": 1396310400000, + "percentage": 0.38414590364041074 + }, + { + "timestamp": 1398902400000, + "percentage": 0.4027949034114262 + }, + { + "timestamp": 1401580800000, + "percentage": 0.39119634109534973 + }, + { + "timestamp": 1404172800000, + "percentage": 0.39365343189248886 + }, + { + "timestamp": 1406851200000, + "percentage": 0.3908259893809185 + }, + { + "timestamp": 1409529600000, + "percentage": 0.386752426324184 + }, + { + "timestamp": 1412121600000, + "percentage": 0.3798018161799614 + }, + { + "timestamp": 1414800000000, + "percentage": 0.3716004131143557 + }, + { + "timestamp": 1417392000000, + "percentage": 0.36080959185948697 + }, + { + "timestamp": 1420070400000, + "percentage": 0.3602221531769458 + }, + { + "timestamp": 1422748800000, + "percentage": 0.34367569336811804 + }, + { + "timestamp": 1425168000000, + "percentage": 0.3538312456104478 + }, + { + "timestamp": 1427846400000, + "percentage": 0.34005691478889627 + }, + { + "timestamp": 1430438400000, + "percentage": 0.33394212863486605 + }, + { + "timestamp": 1433116800000, + "percentage": 0.33768266335505165 + }, + { + "timestamp": 1435708800000, + "percentage": 0.329855657148526 + }, + { + "timestamp": 1438387200000, + "percentage": 0.3344063245325817 + }, + { + "timestamp": 1441065600000, + "percentage": 0.32622333751568383 + }, + { + "timestamp": 1443657600000, + "percentage": 0.32921875991622773 + }, + { + "timestamp": 1446336000000, + "percentage": 0.31493831145824314 + }, + { + "timestamp": 1448928000000, + "percentage": 0.3262025765275972 + }, + { + "timestamp": 1451606400000, + "percentage": 0.3318880567599527 + }, + { + "timestamp": 1454284800000, + "percentage": 0.33677530685518664 + }, + { + "timestamp": 1456790400000, + "percentage": 0.3286770747740345 + }, + { + "timestamp": 1459468800000, + "percentage": 0.29094504461427495 + }, + { + "timestamp": 1462060800000, + "percentage": 0.29628492477740254 + }, + { + "timestamp": 1464739200000, + "percentage": 0.28994342386011346 + }, + { + "timestamp": 1467331200000, + "percentage": 0.2711026119546268 + }, + { + "timestamp": 1470009600000, + "percentage": 0.2821269192950609 + }, + { + "timestamp": 1472688000000, + "percentage": 0.28837871240777496 + }, + { + "timestamp": 1475280000000, + "percentage": 0.26892857949965726 + }, + { + "timestamp": 1477958400000, + "percentage": 0.2593045656648525 + }, + { + "timestamp": 1480550400000, + "percentage": 0.2661960878147993 + }, + { + "timestamp": 1483228800000, + "percentage": 0.2546406304306193 + }, + { + "timestamp": 1485907200000, + "percentage": 0.2565903585097691 + }, + { + "timestamp": 1488326400000, + "percentage": 0.2491506228765572 + }, + { + "timestamp": 1491004800000, + "percentage": 0.24144701694985812 + }, + { + "timestamp": 1493596800000, + "percentage": 0.22869643034702197 + }, + { + "timestamp": 1496275200000, + "percentage": 0.23335366338734057 + }, + { + "timestamp": 1498867200000, + "percentage": 0.2327684818174563 + }, + { + "timestamp": 1501545600000, + "percentage": 0.21959371923096854 + }, + { + "timestamp": 1504224000000, + "percentage": 0.23889462809917356 + }, + { + "timestamp": 1506816000000, + "percentage": 0.22953623393407102 + }, + { + "timestamp": 1509494400000, + "percentage": 0.23825330545438753 + }, + { + "timestamp": 1512086400000, + "percentage": 0.2364701104400571 + }, + { + "timestamp": 1514764800000, + "percentage": 0.23323907632309882 + }, + { + "timestamp": 1517443200000, + "percentage": 0.2333600589266741 + }, + { + "timestamp": 1519862400000, + "percentage": 0.22518273274461234 + }, + { + "timestamp": 1522540800000, + "percentage": 0.2176039119804401 + }, + { + "timestamp": 1525132800000, + "percentage": 0.22118960228060341 + }, + { + "timestamp": 1527811200000, + "percentage": 0.2168697481474478 + }, + { + "timestamp": 1530403200000, + "percentage": 0.2214765100671141 + }, + { + "timestamp": 1533081600000, + "percentage": 0.23084983300224846 + }, + { + "timestamp": 1535760000000, + "percentage": 0.21285100948484864 + }, + { + "timestamp": 1538352000000, + "percentage": 0.1982082346934039 + }, + { + "timestamp": 1541030400000, + "percentage": 0.19699845983022315 + }, + { + "timestamp": 1543640400000, + "percentage": 0.19571346453891003 + }, + { + "timestamp": 1546318800000, + "percentage": 0.18386696280130768 + }, + { + "timestamp": 1548997200000, + "percentage": 0.18791653009942094 + }, + { + "timestamp": 1551416400000, + "percentage": 0.18772597563928037 + }, + { + "timestamp": 1554091200000, + "percentage": 0.17978291706673305 + }, + { + "timestamp": 1556683200000, + "percentage": 0.17306744585821662 + }, + { + "timestamp": 1559361600000, + "percentage": 0.16567210431383145 + }, + { + "timestamp": 1561953600000, + "percentage": 0.15980086931672907 + }, + { + "timestamp": 1564632000000, + "percentage": 0.15628752330018258 + }, + { + "timestamp": 1567310400000, + "percentage": 0.15385309850359993 + }, + { + "timestamp": 1569902400000, + "percentage": 0.1517224411283378 + }, + { + "timestamp": 1572580800000, + "percentage": 0.1408696103472436 + }, + { + "timestamp": 1575176400000, + "percentage": 0.13804893361926482 + } + ], + "installationsPerVersion": [ + { + "version": "1.2", + "total": 364 + }, + { + "version": "1.3-SNAPSHOT (private)", + "total": 1 + } + ], + "installationsPercentagePerVersion": [ + { + "version": "1.2", + "percentage": 0.1376707173627737 + }, + { + "version": "1.3-SNAPSHOT (private)", + "percentage": 3.782162564911365E-4 + } + ], + "currentInstalls": 365, + "trend": -15 + }, + "title": "iOS Device connector", + "url": "http://updates.jenkins-ci.org/download/plugins/ios-device-connector/1.2/ios-device-connector.hpi", + "version": "1.2", + "securityWarnings": null, + "wiki": { + "url": "https://wiki.jenkins-ci.org/display/JENKINS/iOS+Device+Connector+Plugin" + } +} diff --git a/plugins/gatsby-source-jenkinsplugins/__mocks__/wiki.jenkins.io.io-device-connector-plugin.json b/plugins/gatsby-source-jenkinsplugins/__mocks__/wiki.jenkins.io.io-device-connector-plugin.json new file mode 100644 index 000000000..dace4e897 --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/__mocks__/wiki.jenkins.io.io-device-connector-plugin.json @@ -0,0 +1 @@ +{"results":[{"id":"64684255","type":"page","status":"current","title":"iOS Device Connector Plugin","body":{"view":{"value":"\n\n\n\n\n\n\n

Plugin Information

View iOS Device connector on the plugin site for more information.

\n\n\n

This plugin lists up all the iOS devices connected to the master and all the Jenkins slaves, and provide operations to them.

\n\n

Specifically, the current version provides the following functionalities:

\n\n\n\n\n

\n\n

Feedback requested

\n

This plugin came into being as a Kohsuke's post-JavaOne hobby project, to explore what needs to be done in order to make iOS app development properly automated. If you do iOS app development for real, please let us know what needs to be done!

\n\n\n

Changelog

\n

Version 1.2 (Oct 10, 2012)

\n\n\n\n

Version 1.1 (Oct 8, 2012)

\n\n\n\n

Version 1.0 (Oct 7, 2012)

\n","representation":"storage","_expandable":{"webresource":"","content":"/rest/api/content/64684255"}},"_expandable":{"editor":"","export_view":"","styled_view":"","storage":"","anonymous_export_view":""}},"extensions":{"position":"none"},"_links":{"webui":"/display/JENKINS/iOS+Device+Connector+Plugin","edit":"/pages/resumedraft.action?draftId=64684255","tinyui":"/x/3wDbAw","self":"https://wiki.jenkins.io/rest/api/content/64684255"},"_expandable":{"container":"/rest/api/space/JENKINS","metadata":"","operations":"","children":"/rest/api/content/64684255/child","restrictions":"/rest/api/content/64684255/restriction/byOperation","history":"/rest/api/content/64684255/history","ancestors":"","version":"","descendants":"/rest/api/content/64684255/descendant","space":"/rest/api/space/JENKINS"}}],"start":0,"limit":25,"size":1,"_links":{"self":"https://wiki.jenkins.io/rest/api/content?expand=body.view&title=iOS+Device+Connector+Plugin","base":"https://wiki.jenkins.io","context":""}} diff --git a/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap b/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap new file mode 100644 index 000000000..68ef4c3db --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/__snapshots__/utils.test.js.snap @@ -0,0 +1,914 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Utils Get plugin data for a wiki based plugin 1`] = ` +Object { + "buildDate": "2012-10-10", + "categories": Array [ + "languagesPlatforms", + "buildManagement", + ], + "children": Array [], + "dependencies": Array [ + Object { + "implied": true, + "name": "external-monitor-job", + "optional": false, + "title": "External Monitor Job Type", + "version": "1.0", + }, + Object { + "implied": true, + "name": "ldap", + "optional": false, + "title": "LDAP", + "version": "1.0", + }, + Object { + "implied": true, + "name": "pam-auth", + "optional": false, + "title": "PAM Authentication", + "version": "1.0", + }, + Object { + "implied": true, + "name": "mailer", + "optional": false, + "title": "Mailer", + "version": "1.2", + }, + Object { + "implied": true, + "name": "matrix-auth", + "optional": false, + "title": "Matrix Authorization Strategy", + "version": "1.0.2", + }, + Object { + "implied": true, + "name": "windows-slaves", + "optional": false, + "title": "WMI Windows Agents", + "version": "1.0", + }, + Object { + "implied": true, + "name": "antisamy-markup-formatter", + "optional": false, + "title": "OWASP Markup Formatter", + "version": "1.0", + }, + Object { + "implied": true, + "name": "matrix-project", + "optional": false, + "title": "Matrix Project", + "version": "1.0", + }, + Object { + "implied": true, + "name": "junit", + "optional": false, + "title": "JUnit", + "version": "1.0", + }, + Object { + "implied": true, + "name": "bouncycastle-api", + "optional": false, + "title": "bouncycastle API", + "version": "2.16.0", + }, + Object { + "implied": true, + "name": "command-launcher", + "optional": false, + "title": "Command Agent Launcher", + "version": "1.0", + }, + Object { + "implied": true, + "name": "jdk-tool", + "optional": false, + "title": "Oracle Java SE Development Kit Installer", + "version": "1.0", + }, + Object { + "implied": true, + "name": "jaxb", + "optional": false, + "title": "JAXB", + "version": "2.3.0", + }, + Object { + "implied": true, + "name": "trilead-api", + "optional": false, + "title": "Trilead API", + "version": "1.0.4", + }, + ], + "excerpt": "Talks to iOS devices connected to slaves and do stuff.", + "firstRelease": "2012-10-07T18:59:35.16Z", + "gav": "org.jenkins-ci.plugins:ios-device-connector:1.2", + "id": "ios-device-connector", + "internal": Object { + "contentDigest": "7da41342fb756c851d4b5a9b6b6f9f3e", + "type": "JenkinsPlugin", + }, + "labels": Array [ + "builder", + "ios", + ], + "maintainers": Array [ + Object { + "email": null, + "id": "kohsuke", + "name": null, + }, + ], + "name": "ios-device-connector", + "parent": null, + "previousTimestamp": "2012-10-08T20:04:52.00Z", + "previousVersion": "1.1", + "releaseTimestamp": "2012-10-10T17:27:58.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, + "sha1": "B2z2wTyA8l5uwz9HqD+xhG9Hjns=", + "stats": Object { + "currentInstalls": 365, + "installations": Array [ + Object { + "timestamp": 1349049600000, + "total": 55, + }, + Object { + "timestamp": 1351728000000, + "total": 97, + }, + Object { + "timestamp": 1354320000000, + "total": 123, + }, + Object { + "timestamp": 1356998400000, + "total": 177, + }, + Object { + "timestamp": 1359676800000, + "total": 186, + }, + Object { + "timestamp": 1362096000000, + "total": 192, + }, + Object { + "timestamp": 1364774400000, + "total": 229, + }, + Object { + "timestamp": 1367366400000, + "total": 235, + }, + Object { + "timestamp": 1370044800000, + "total": 256, + }, + Object { + "timestamp": 1372636800000, + "total": 262, + }, + Object { + "timestamp": 1375315200000, + "total": 282, + }, + Object { + "timestamp": 1377993600000, + "total": 295, + }, + Object { + "timestamp": 1380585600000, + "total": 302, + }, + Object { + "timestamp": 1383264000000, + "total": 299, + }, + Object { + "timestamp": 1385856000000, + "total": 300, + }, + Object { + "timestamp": 1388534400000, + "total": 312, + }, + Object { + "timestamp": 1391212800000, + "total": 318, + }, + Object { + "timestamp": 1393632000000, + "total": 330, + }, + Object { + "timestamp": 1396310400000, + "total": 321, + }, + Object { + "timestamp": 1398902400000, + "total": 343, + }, + Object { + "timestamp": 1401580800000, + "total": 337, + }, + Object { + "timestamp": 1404172800000, + "total": 360, + }, + Object { + "timestamp": 1406851200000, + "total": 357, + }, + Object { + "timestamp": 1409529600000, + "total": 371, + }, + Object { + "timestamp": 1412121600000, + "total": 376, + }, + Object { + "timestamp": 1414800000000, + "total": 367, + }, + Object { + "timestamp": 1417392000000, + "total": 356, + }, + Object { + "timestamp": 1420070400000, + "total": 371, + }, + Object { + "timestamp": 1422748800000, + "total": 357, + }, + Object { + "timestamp": 1425168000000, + "total": 398, + }, + Object { + "timestamp": 1427846400000, + "total": 380, + }, + Object { + "timestamp": 1430438400000, + "total": 373, + }, + Object { + "timestamp": 1433116800000, + "total": 397, + }, + Object { + "timestamp": 1435708800000, + "total": 399, + }, + Object { + "timestamp": 1438387200000, + "total": 401, + }, + Object { + "timestamp": 1441065600000, + "total": 403, + }, + Object { + "timestamp": 1443657600000, + "total": 415, + }, + Object { + "timestamp": 1446336000000, + "total": 400, + }, + Object { + "timestamp": 1448928000000, + "total": 414, + }, + Object { + "timestamp": 1451606400000, + "total": 421, + }, + Object { + "timestamp": 1454284800000, + "total": 363, + }, + Object { + "timestamp": 1456790400000, + "total": 360, + }, + Object { + "timestamp": 1459468800000, + "total": 359, + }, + Object { + "timestamp": 1462060800000, + "total": 386, + }, + Object { + "timestamp": 1464739200000, + "total": 390, + }, + Object { + "timestamp": 1467331200000, + "total": 353, + }, + Object { + "timestamp": 1470009600000, + "total": 373, + }, + Object { + "timestamp": 1472688000000, + "total": 385, + }, + Object { + "timestamp": 1475280000000, + "total": 357, + }, + Object { + "timestamp": 1477958400000, + "total": 354, + }, + Object { + "timestamp": 1480550400000, + "total": 356, + }, + Object { + "timestamp": 1483228800000, + "total": 359, + }, + Object { + "timestamp": 1485907200000, + "total": 358, + }, + Object { + "timestamp": 1488326400000, + "total": 374, + }, + Object { + "timestamp": 1491004800000, + "total": 348, + }, + Object { + "timestamp": 1493596800000, + "total": 345, + }, + Object { + "timestamp": 1496275200000, + "total": 352, + }, + Object { + "timestamp": 1498867200000, + "total": 350, + }, + Object { + "timestamp": 1501545600000, + "total": 339, + }, + Object { + "timestamp": 1504224000000, + "total": 370, + }, + Object { + "timestamp": 1506816000000, + "total": 357, + }, + Object { + "timestamp": 1509494400000, + "total": 384, + }, + Object { + "timestamp": 1512086400000, + "total": 361, + }, + Object { + "timestamp": 1514764800000, + "total": 372, + }, + Object { + "timestamp": 1517443200000, + "total": 358, + }, + Object { + "timestamp": 1519862400000, + "total": 370, + }, + Object { + "timestamp": 1522540800000, + "total": 356, + }, + Object { + "timestamp": 1525132800000, + "total": 367, + }, + Object { + "timestamp": 1527811200000, + "total": 367, + }, + Object { + "timestamp": 1530403200000, + "total": 396, + }, + Object { + "timestamp": 1533081600000, + "total": 423, + }, + Object { + "timestamp": 1535760000000, + "total": 410, + }, + Object { + "timestamp": 1538352000000, + "total": 427, + }, + Object { + "timestamp": 1541030400000, + "total": 440, + }, + Object { + "timestamp": 1543640400000, + "total": 429, + }, + Object { + "timestamp": 1546318800000, + "total": 428, + }, + Object { + "timestamp": 1548997200000, + "total": 430, + }, + Object { + "timestamp": 1551416400000, + "total": 473, + }, + Object { + "timestamp": 1554091200000, + "total": 455, + }, + Object { + "timestamp": 1556683200000, + "total": 446, + }, + Object { + "timestamp": 1559361600000, + "total": 417, + }, + Object { + "timestamp": 1561953600000, + "total": 425, + }, + Object { + "timestamp": 1564632000000, + "total": 410, + }, + Object { + "timestamp": 1567310400000, + "total": 409, + }, + Object { + "timestamp": 1569902400000, + "total": 407, + }, + Object { + "timestamp": 1572580800000, + "total": 380, + }, + Object { + "timestamp": 1575176400000, + "total": 365, + }, + ], + "installationsPerVersion": Array [ + Object { + "total": 364, + "version": "1.2", + }, + Object { + "total": 1, + "version": "1.3-SNAPSHOT (private)", + }, + ], + "installationsPercentage": Array [ + Object { + "percentage": 0.10514242018734468, + "timestamp": 1349049600000, + }, + Object { + "percentage": 0.18167175472440208, + "timestamp": 1351728000000, + }, + Object { + "percentage": 0.2390159538291133, + "timestamp": 1354320000000, + }, + Object { + "percentage": 0.3111048616725841, + "timestamp": 1356998400000, + }, + Object { + "percentage": 0.3244148323856699, + "timestamp": 1359676800000, + }, + Object { + "percentage": 0.3109664253437637, + "timestamp": 1362096000000, + }, + Object { + "percentage": 0.35684233490198525, + "timestamp": 1364774400000, + }, + Object { + "percentage": 0.35990504632820275, + "timestamp": 1367366400000, + }, + Object { + "percentage": 0.38952541805511176, + "timestamp": 1370044800000, + }, + Object { + "percentage": 0.37967712952496885, + "timestamp": 1372636800000, + }, + Object { + "percentage": 0.4127090986257665, + "timestamp": 1375315200000, + }, + Object { + "percentage": 0.4217961366333519, + "timestamp": 1377993600000, + }, + Object { + "percentage": 0.4070464868653377, + "timestamp": 1380585600000, + }, + Object { + "percentage": 0.404518703916661, + "timestamp": 1383264000000, + }, + Object { + "percentage": 0.4160829946880071, + "timestamp": 1385856000000, + }, + Object { + "percentage": 0.4048898232500195, + "timestamp": 1388534400000, + }, + Object { + "percentage": 0.4044823770335415, + "timestamp": 1391212800000, + }, + Object { + "percentage": 0.3987915407854985, + "timestamp": 1393632000000, + }, + Object { + "percentage": 0.38414590364041074, + "timestamp": 1396310400000, + }, + Object { + "percentage": 0.4027949034114262, + "timestamp": 1398902400000, + }, + Object { + "percentage": 0.39119634109534973, + "timestamp": 1401580800000, + }, + Object { + "percentage": 0.39365343189248886, + "timestamp": 1404172800000, + }, + Object { + "percentage": 0.3908259893809185, + "timestamp": 1406851200000, + }, + Object { + "percentage": 0.386752426324184, + "timestamp": 1409529600000, + }, + Object { + "percentage": 0.3798018161799614, + "timestamp": 1412121600000, + }, + Object { + "percentage": 0.3716004131143557, + "timestamp": 1414800000000, + }, + Object { + "percentage": 0.36080959185948697, + "timestamp": 1417392000000, + }, + Object { + "percentage": 0.3602221531769458, + "timestamp": 1420070400000, + }, + Object { + "percentage": 0.34367569336811804, + "timestamp": 1422748800000, + }, + Object { + "percentage": 0.3538312456104478, + "timestamp": 1425168000000, + }, + Object { + "percentage": 0.34005691478889627, + "timestamp": 1427846400000, + }, + Object { + "percentage": 0.33394212863486605, + "timestamp": 1430438400000, + }, + Object { + "percentage": 0.33768266335505165, + "timestamp": 1433116800000, + }, + Object { + "percentage": 0.329855657148526, + "timestamp": 1435708800000, + }, + Object { + "percentage": 0.3344063245325817, + "timestamp": 1438387200000, + }, + Object { + "percentage": 0.32622333751568383, + "timestamp": 1441065600000, + }, + Object { + "percentage": 0.32921875991622773, + "timestamp": 1443657600000, + }, + Object { + "percentage": 0.31493831145824314, + "timestamp": 1446336000000, + }, + Object { + "percentage": 0.3262025765275972, + "timestamp": 1448928000000, + }, + Object { + "percentage": 0.3318880567599527, + "timestamp": 1451606400000, + }, + Object { + "percentage": 0.33677530685518664, + "timestamp": 1454284800000, + }, + Object { + "percentage": 0.3286770747740345, + "timestamp": 1456790400000, + }, + Object { + "percentage": 0.29094504461427495, + "timestamp": 1459468800000, + }, + Object { + "percentage": 0.29628492477740254, + "timestamp": 1462060800000, + }, + Object { + "percentage": 0.28994342386011346, + "timestamp": 1464739200000, + }, + Object { + "percentage": 0.2711026119546268, + "timestamp": 1467331200000, + }, + Object { + "percentage": 0.2821269192950609, + "timestamp": 1470009600000, + }, + Object { + "percentage": 0.28837871240777496, + "timestamp": 1472688000000, + }, + Object { + "percentage": 0.26892857949965726, + "timestamp": 1475280000000, + }, + Object { + "percentage": 0.2593045656648525, + "timestamp": 1477958400000, + }, + Object { + "percentage": 0.2661960878147993, + "timestamp": 1480550400000, + }, + Object { + "percentage": 0.2546406304306193, + "timestamp": 1483228800000, + }, + Object { + "percentage": 0.2565903585097691, + "timestamp": 1485907200000, + }, + Object { + "percentage": 0.2491506228765572, + "timestamp": 1488326400000, + }, + Object { + "percentage": 0.24144701694985812, + "timestamp": 1491004800000, + }, + Object { + "percentage": 0.22869643034702197, + "timestamp": 1493596800000, + }, + Object { + "percentage": 0.23335366338734057, + "timestamp": 1496275200000, + }, + Object { + "percentage": 0.2327684818174563, + "timestamp": 1498867200000, + }, + Object { + "percentage": 0.21959371923096854, + "timestamp": 1501545600000, + }, + Object { + "percentage": 0.23889462809917356, + "timestamp": 1504224000000, + }, + Object { + "percentage": 0.22953623393407102, + "timestamp": 1506816000000, + }, + Object { + "percentage": 0.23825330545438753, + "timestamp": 1509494400000, + }, + Object { + "percentage": 0.2364701104400571, + "timestamp": 1512086400000, + }, + Object { + "percentage": 0.23323907632309882, + "timestamp": 1514764800000, + }, + Object { + "percentage": 0.2333600589266741, + "timestamp": 1517443200000, + }, + Object { + "percentage": 0.22518273274461234, + "timestamp": 1519862400000, + }, + Object { + "percentage": 0.2176039119804401, + "timestamp": 1522540800000, + }, + Object { + "percentage": 0.22118960228060341, + "timestamp": 1525132800000, + }, + Object { + "percentage": 0.2168697481474478, + "timestamp": 1527811200000, + }, + Object { + "percentage": 0.2214765100671141, + "timestamp": 1530403200000, + }, + Object { + "percentage": 0.23084983300224846, + "timestamp": 1533081600000, + }, + Object { + "percentage": 0.21285100948484864, + "timestamp": 1535760000000, + }, + Object { + "percentage": 0.1982082346934039, + "timestamp": 1538352000000, + }, + Object { + "percentage": 0.19699845983022315, + "timestamp": 1541030400000, + }, + Object { + "percentage": 0.19571346453891003, + "timestamp": 1543640400000, + }, + Object { + "percentage": 0.18386696280130768, + "timestamp": 1546318800000, + }, + Object { + "percentage": 0.18791653009942094, + "timestamp": 1548997200000, + }, + Object { + "percentage": 0.18772597563928037, + "timestamp": 1551416400000, + }, + Object { + "percentage": 0.17978291706673305, + "timestamp": 1554091200000, + }, + Object { + "percentage": 0.17306744585821662, + "timestamp": 1556683200000, + }, + Object { + "percentage": 0.16567210431383145, + "timestamp": 1559361600000, + }, + Object { + "percentage": 0.15980086931672907, + "timestamp": 1561953600000, + }, + Object { + "percentage": 0.15628752330018258, + "timestamp": 1564632000000, + }, + Object { + "percentage": 0.15385309850359993, + "timestamp": 1567310400000, + }, + Object { + "percentage": 0.1517224411283378, + "timestamp": 1569902400000, + }, + Object { + "percentage": 0.1408696103472436, + "timestamp": 1572580800000, + }, + Object { + "percentage": 0.13804893361926482, + "timestamp": 1575176400000, + }, + ], + "installationsPercentagePerVersion": Array [ + Object { + "percentage": 0.1376707173627737, + "version": "1.2", + }, + Object { + "percentage": 0.0003782162564911365, + "version": "1.3-SNAPSHOT (private)", + }, + ], + "trend": -15, + }, + "title": "iOS Device connector", + "url": "http://updates.jenkins-ci.org/download/plugins/ios-device-connector/1.2/ios-device-connector.hpi", + "version": "1.2", + "wiki": Object { + "content": " + + +

This plugin lists up all the iOS devices connected to the master and all the Jenkins slaves, and provide operations to them.

+ +

Specifically, the current version provides the following functionalities:

+ + + + +

+ +

Feedback requested

+

This plugin came into being as a Kohsuke's post-JavaOne hobby project, to explore what needs to be done in order to make iOS app development properly automated. If you do iOS app development for real, please let us know what needs to be done!

+ + +

Changelog

+

Version 1.2 (Oct 10, 2012)

+ + + +

Version 1.1 (Oct 8, 2012)

+ + + +

Version 1.0 (Oct 7, 2012)

+", + "url": "https://wiki.jenkins-ci.org/display/JENKINS/iOS+Device+Connector+Plugin", + }, +} +`; diff --git a/plugins/gatsby-source-jenkinsplugins/gatsby-node.js b/plugins/gatsby-source-jenkinsplugins/gatsby-node.js index 6bb7775e5..53816cb89 100644 --- a/plugins/gatsby-source-jenkinsplugins/gatsby-node.js +++ b/plugins/gatsby-source-jenkinsplugins/gatsby-node.js @@ -1,8 +1,3 @@ -/* eslint-disable no-console */ -const axios = require('axios'); -const crypto = require('crypto'); -const {execSync} = require('child_process'); - /* plugins: ` firstRelease: Date @@ -52,133 +47,13 @@ plugins: ` ` */ -const requestGET = ({url, reporter}) => { - const activity = reporter.activityTimer(`Fetching '${url}'`); - activity.start(); - - return axios - .get(url) - .then((results) => { - activity.end(); - - if (results.status !== 200) { - throw results.data; - } - return results.data; - }); -}; - -const fetchPluginData = async ({createNode, reporter}) => { - const sectionActivity = reporter.activityTimer('fetch plugins info'); - sectionActivity.start(); - const promises = []; - let page = 1; - let pluginsContainer; - do { - const url = `https://plugins.jenkins.io/api/plugins/?limit=100&page=${page}`; - pluginsContainer = await requestGET({url, reporter}); +const { + fetchSiteInfo, + fetchPluginData, + fetchCategoryData, + fetchLabelData +} = require('./utils.js'); - for (const plugin of pluginsContainer.plugins) { - const promise = ( - process.env.GET_CONTENT - ? requestGET({reporter, url: `https://plugins.jenkins.io/api/plugin/${plugin.name}`}) - : Promise.resolve(plugin) - ); - promises.push(promise.then(pluginData => { - pluginData.wiki = pluginData.wiki || {}; - // absolutely required fields - pluginData.wiki.content = pluginData.wiki.content || ''; - pluginData.wiki.url = pluginData.wiki.url || ''; - return createNode({ - ...pluginData, - id: pluginData.name.trim(), - parent: null, - children: [], - internal: { - type: 'JenkinsPlugin', - contentDigest: crypto.createHash('md5').update(`plugin${pluginData.name.trim()}`).digest('hex') - } - }); - })); - } - page = pluginsContainer.page + 1; - } while (!page || pluginsContainer.page <= pluginsContainer.pages); - await Promise.all(promises); - sectionActivity.end(); -}; - -const fetchCategoryData = async ({createNode, reporter}) => { - const sectionActivity = reporter.activityTimer('fetch categories info'); - sectionActivity.start(); - const url = 'https://plugins.jenkins.io/api/categories/?limit=100'; - const categoriesContainer = await requestGET({url, reporter}); - - for (const category of categoriesContainer.categories) { - createNode({ - ...category, - id: category.id.trim(), - parent: null, - children: [], - internal: { - type: 'JenkinsPluginCategory', - contentDigest: crypto - .createHash('md5') - .update(`category${category.name}`) - .digest('hex') - } - }); - } - sectionActivity.end(); -}; - -const fetchLabelData = async ({createNode, reporter}) => { - const sectionActivity = reporter.activityTimer('fetch labels info'); - sectionActivity.start(); - const url = 'https://plugins.jenkins.io/api/labels/?limit=100'; - const labelsContainer = await requestGET({url, reporter}); - - for (const label of labelsContainer.labels) { - createNode({ - ...label, - id: label.id.trim(), - parent: null, - children: [], - internal: { - type: 'JenkinsPluginLabel', - contentDigest: crypto - .createHash('md5') - .update(`label${label.name}`) - .digest('hex') - } - }); - } - sectionActivity.end(); -}; - -const fetchSiteInfo = async ({createNode, reporter}) => { - const sectionActivity = reporter.activityTimer('fetch plugin api info'); - sectionActivity.start(); - const url = 'https://plugins.jenkins.io/api/info'; - const info = await requestGET({url, reporter}); - - createNode({ - api: { - ...info - }, - website: { - commit: execSync('git rev-parse HEAD').toString().trim(), - version: require('find-package-json')().next().value.version, - }, - id: 'pluginSiteInfo', - parent: null, - children: [], - internal: { - type: 'JenkinsPluginSiteInfo', - contentDigest: crypto.createHash('md5').update('pluginSiteInfo').digest('hex') - } - }); - sectionActivity.end(); -}; exports.sourceNodes = async ( {actions, reporter}, diff --git a/plugins/gatsby-source-jenkinsplugins/utils.js b/plugins/gatsby-source-jenkinsplugins/utils.js new file mode 100644 index 000000000..3f526336a --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/utils.js @@ -0,0 +1,191 @@ +/* eslint-disable no-console */ +const axios = require('axios'); +const crypto = require('crypto'); +const cheerio = require('cheerio'); +const {execSync} = require('child_process'); +const URL = require('url'); +const axiosRetry = require('axios-retry'); + +axiosRetry(axios, {retries: 3}); + +const requestGET = ({url, reporter}) => { + const activity = reporter.activityTimer(`Fetching '${url}'`); + activity.start(); + + return axios + .get(url) + .then((results) => { + activity.end(); + + if (results.status !== 200) { + throw results.data; + } + return results.data; + }); +}; + +function getContentFromConfluencePage(url, content) { + const $ = cheerio.load(cheerio.load(content)('.wiki-content').html()); + + $('.conf-macro.output-inline th:contains("Plugin Information")').parents('table').remove(); + + // Remove any table of contents + $('.toc').remove(); + + // Replace href/src with the wiki url + $('[href]').each((idx, elm) => { + $(elm).attr('href', URL.resolve(url, $(elm).attr('href'))); + }); + $('[src]').each((idx, elm) => { + $(elm).attr('src', URL.resolve(url, $(elm).attr('src'))); + }); + return ($('body') || $).html(); +} + +const pluginWikiUrlRe = /^https?:\/\/wiki.jenkins(?:-ci.org|.io)\/display\/(?:jenkins|hudson)\/([^/]*)\/?$/i; +const getPluginContent = async ({plugin, reporter}) => { + plugin.id = plugin.id || plugin.name; + plugin.wiki = plugin.wiki || {}; + // absolutely required fields + plugin.wiki.content = plugin.wiki.content || ''; + plugin.wiki.url = plugin.wiki.url || ''; + + if (!process.env.GET_CONTENT) { + return plugin; + } + let matches; + if ((matches = pluginWikiUrlRe.exec(plugin.wiki.url)) != null) { + try { + return await requestGET({ + reporter, + url: `https://wiki.jenkins.io/rest/api/content?expand=body.view&title=${matches[1]}` + }).then(async data => { + plugin.wiki.content = await getContentFromConfluencePage( + 'https://wiki.jenkins.io/', + `${data.results[0].body.view.value}` + ); + return plugin; + }); + } catch (e) { + console.error(`Error fetching wiki content for ${plugin.name}`, e); + } + } + + return requestGET({reporter, url: `https://plugins.jenkins.io/api/plugin/${plugin.name}`}).then(data => { + plugin.wiki.content = data.wiki.content || ''; + return plugin; + }); +}; + +const fetchPluginData = async ({createNode, reporter}) => { + const sectionActivity = reporter.activityTimer('fetch plugins info'); + sectionActivity.start(); + const promises = []; + let page = 1; + let pluginsContainer; + do { + const url = `https://plugins.jenkins.io/api/plugins/?limit=100&page=${page}`; + pluginsContainer = await requestGET({url, reporter}); + + for (const plugin of pluginsContainer.plugins) { + promises.push(getPluginContent({plugin, reporter}).then(pluginData => { + return createNode({ + ...pluginData, + id: pluginData.name.trim(), + parent: null, + children: [], + internal: { + type: 'JenkinsPlugin', + contentDigest: crypto.createHash('md5').update(`plugin${pluginData.name.trim()}`).digest('hex') + } + }); + })); + } + page = pluginsContainer.page + 1; + } while (!page || pluginsContainer.page < pluginsContainer.pages); + await Promise.all(promises); + sectionActivity.end(); +}; + +const fetchCategoryData = async ({createNode, reporter}) => { + const sectionActivity = reporter.activityTimer('fetch categories info'); + sectionActivity.start(); + const url = 'https://plugins.jenkins.io/api/categories/?limit=100'; + const categoriesContainer = await requestGET({url, reporter}); + + for (const category of categoriesContainer.categories) { + createNode({ + ...category, + id: category.id.trim(), + parent: null, + children: [], + internal: { + type: 'JenkinsPluginCategory', + contentDigest: crypto + .createHash('md5') + .update(`category${category.name}`) + .digest('hex') + } + }); + } + sectionActivity.end(); +}; + +const fetchLabelData = async ({createNode, reporter}) => { + const sectionActivity = reporter.activityTimer('fetch labels info'); + sectionActivity.start(); + const url = 'https://plugins.jenkins.io/api/labels/?limit=100'; + const labelsContainer = await requestGET({url, reporter}); + + for (const label of labelsContainer.labels) { + createNode({ + ...label, + id: label.id.trim(), + parent: null, + children: [], + internal: { + type: 'JenkinsPluginLabel', + contentDigest: crypto + .createHash('md5') + .update(`label${label.name}`) + .digest('hex') + } + }); + } + sectionActivity.end(); +}; + +const fetchSiteInfo = async ({createNode, reporter}) => { + const sectionActivity = reporter.activityTimer('fetch plugin api info'); + sectionActivity.start(); + const url = 'https://plugins.jenkins.io/api/info'; + const info = await requestGET({url, reporter}); + + createNode({ + api: { + ...info + }, + website: { + commit: execSync('git rev-parse HEAD').toString().trim(), + version: require('find-package-json')().next().value.version, + }, + id: 'pluginSiteInfo', + parent: null, + children: [], + internal: { + type: 'JenkinsPluginSiteInfo', + contentDigest: crypto.createHash('md5').update('pluginSiteInfo').digest('hex') + } + }); + sectionActivity.end(); +}; + +module.exports = { + fetchSiteInfo, + fetchLabelData, + fetchCategoryData, + fetchPluginData, + getPluginContent, + requestGET +} +; diff --git a/plugins/gatsby-source-jenkinsplugins/utils.test.js b/plugins/gatsby-source-jenkinsplugins/utils.test.js new file mode 100644 index 000000000..4cfb41892 --- /dev/null +++ b/plugins/gatsby-source-jenkinsplugins/utils.test.js @@ -0,0 +1,50 @@ +/** + * @jest-environment node + */ +const fs = require('fs'); +const path = require('path'); +const utils = require('./utils.js'); +const nock = require('nock'); +nock.disableNetConnect(); + +process.env.GET_CONTENT = true; + +describe('Utils', () => { + let _reporter; + afterEach(() => { + nock.cleanAll(); + }); + beforeEach(async () => { + _reporter = { + panic: (...args) => { throw args[0]; }, + activityTimer: () => { + return { + start: jest.fn(), + end: jest.fn(), + }; + } + }; + }); + it('Get plugin data for a wiki based plugin', async () => { + nock('https://plugins.jenkins.io') + .get('/api/plugins/?limit=100&page=1') + .reply(200, { + 'plugins': [ + JSON.parse( + await fs.promises.readFile(path.join(__dirname, '__mocks__', 'plugins.jenkins.io.api.plugin.ios-device-connector.json')).then(d => d.toString()) + ) + ], + 'page': 1, + 'pages': 1, + 'total': 1, + 'limit': 100 + }, {'Content-Type': 'application/json'}); + nock('https://wiki.jenkins.io') + .get('/rest/api/content?expand=body.view&title=iOS+Device+Connector+Plugin') + .replyWithFile(200, path.join(__dirname, '__mocks__', 'wiki.jenkins.io.io-device-connector-plugin.json'), {'Content-Type': 'application/json'}); + + const createNode = jest.fn(); + await utils.fetchPluginData({createNode, reporter: _reporter}); + expect(createNode.mock.calls[0][0]).toMatchSnapshot(); + }); +}); diff --git a/yarn.lock b/yarn.lock index 057fee5eb..ef2bc9d9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2214,6 +2214,13 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.1.tgz#7e33d8f7d449b3f673cd72deb9abdc552dbe528e" integrity sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug== +axios-retry@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.1.2.tgz#4f4dcbefb0b434e22b72bd5e28a027d77b8a3458" + integrity sha512-+X0mtJ3S0mmia1kTVi1eA3DAC+oWnT2A29g3CpkzcBPMT6vJm+hn/WiV9wPt/KXLHVmg5zev9mWqkPx7bHMovg== + dependencies: + is-retry-allowed "^1.1.0" + axios@^0.19.0: version "0.19.1" resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.1.tgz#8a6a04eed23dfe72747e1dd43c604b8f1677b5aa" @@ -9505,6 +9512,17 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== +nock@^11.7.2: + version "11.7.2" + resolved "https://registry.yarnpkg.com/nock/-/nock-11.7.2.tgz#4cee4fa838dc3635c074c5b3436bcdec7f7ee213" + integrity sha512-7swr5bL1xBZ5FctyubjxEVySXOSebyqcL7Vy1bx1nS9IUqQWj81cmKjVKJLr8fHhtzI1MV8nyCdENA/cGcY1+Q== + dependencies: + debug "^4.1.0" + json-stringify-safe "^5.0.1" + lodash "^4.17.13" + mkdirp "^0.5.0" + propagate "^2.0.0" + node-abi@^2.7.0: version "2.13.0" resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.13.0.tgz#e2f2ec444d0aca3ea1b3874b6de41d1665828f63" @@ -11480,6 +11498,11 @@ prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.1, object-assign "^4.1.1" react-is "^16.8.1" +propagate@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45" + integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag== + proto-list@~1.2.1: version "1.2.4" resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"