|
1 |
| -var https = require('https'); |
2 |
| - |
3 |
| - |
4 |
| -var get_github_readme = function(repo, branch, callback) { |
5 |
| - var repo_parts = repo.split('/'); |
6 |
| - |
7 |
| - var readme = ""; |
8 |
| - var url = 'https://raw.githubusercontent.com/' + repo_parts[0] + '/' + repo_parts[1] + '/' + branch + '/README.md' |
9 |
| - var request = https.get(url, function(response) { |
10 |
| - response.on('data', function(chunk) { |
11 |
| - readme += chunk; |
12 |
| - }); |
13 |
| - response.on('end', function() { |
14 |
| - callback(readme); |
15 |
| - }); |
16 |
| - }); |
| 1 | +var https = require("https"); |
| 2 | + |
| 3 | +var get_github_readme = function (repo, branch, callback) { |
| 4 | + var repo_parts = repo.split("/"); |
| 5 | + |
| 6 | + var readme = ""; |
| 7 | + var url = |
| 8 | + "https://raw.githubusercontent.com/" + |
| 9 | + repo_parts[0] + |
| 10 | + "/" + |
| 11 | + repo_parts[1] + |
| 12 | + "/" + |
| 13 | + branch + |
| 14 | + "/README.md"; |
| 15 | + var request = https.get(url, function (response) { |
| 16 | + response.on("data", function (chunk) { |
| 17 | + readme += chunk; |
| 18 | + }); |
| 19 | + response.on("end", function () { |
| 20 | + callback(readme); |
| 21 | + }); |
| 22 | + }); |
17 | 23 | };
|
18 | 24 |
|
19 |
| - |
20 | 25 | var get_dockerhub_readme = function (repo, callback) {
|
21 |
| - const dockerHubAPI = require('docker-hub-api'); |
| 26 | + const dockerHubAPI = require("docker-hub-api"); |
22 | 27 |
|
23 |
| - var repo_parts = repo.split('/'); |
| 28 | + var repo_parts = repo.split("/"); |
24 | 29 |
|
25 |
| - var repo = dockerHubAPI.repository(repo_parts[0], repo_parts[1]).then(function(info) { |
26 |
| - var desc = info['full_description'] |
27 |
| - if (desc == null) { |
28 |
| - desc = '' |
29 |
| - } |
| 30 | + var repo = dockerHubAPI |
| 31 | + .repository(repo_parts[0], repo_parts[1]) |
| 32 | + .then(function (info) { |
| 33 | + var desc = info["full_description"]; |
| 34 | + if (desc == null) { |
| 35 | + desc = ""; |
| 36 | + } |
30 | 37 |
|
31 |
| - callback(desc); |
32 |
| - }); |
| 38 | + callback(desc); |
| 39 | + }); |
33 | 40 | };
|
34 | 41 |
|
35 |
| -var update_dockerhub_readme = function(user, pass, repo, full_desc, callback) { |
36 |
| - const dockerHubAPI = require('docker-hub-api'); |
| 42 | +var update_dockerhub_readme = function (user, pass, repo, full_desc, callback) { |
| 43 | + const dockerHubAPI = require("docker-hub-api"); |
| 44 | + |
| 45 | + var repo_parts = repo.split("/"); |
37 | 46 |
|
38 |
| - |
39 |
| - var repo_parts = repo.split('/'); |
| 47 | + dockerHubAPI.login(user, pass).then(function (info) { |
| 48 | + var descriptions = { |
| 49 | + full: full_desc, |
| 50 | + }; |
40 | 51 |
|
41 |
| - dockerHubAPI.login(user, pass).then(function(info) { |
42 |
| - var descriptions = { |
43 |
| - full: full_desc |
44 |
| - }; |
45 |
| - |
46 |
| - dockerHubAPI.setRepositoryDescription(repo_parts[0], repo_parts[1], descriptions); |
| 52 | + dockerHubAPI.setRepositoryDescription( |
| 53 | + repo_parts[0], |
| 54 | + repo_parts[1], |
| 55 | + descriptions |
| 56 | + ); |
47 | 57 |
|
48 |
| - callback(); |
49 |
| - }); |
| 58 | + callback(); |
| 59 | + }); |
50 | 60 | };
|
51 | 61 |
|
52 | 62 | function run() {
|
53 |
| - const fs = require('fs') |
54 |
| - |
55 |
| - var dockerhub_username = process.env.DOCKERHUB_USERNAME |
56 |
| - var dockerhub_password = process.env.DOCKERHUB_PASSWORD |
57 |
| - |
58 |
| - var github_repo = process.env.GIT_REPOSITORY; |
59 |
| - var dockerhub_repo = process.env.DOCKER_REPOSITORY; |
60 |
| - |
61 |
| - var branch = typeof process.env.GIT_BRANCH !== 'undefined' ? process.env.GIT_BRANCH : 'master'; |
62 |
| - |
63 |
| - // Get github readme |
64 |
| - console.log('Getting github readme for ' + github_repo); |
65 |
| - get_github_readme(github_repo, branch, function(github_readme) { |
66 |
| - |
67 |
| - // Get dockerhub full description |
68 |
| - console.log('Getting dockerhub full description for ' + dockerhub_repo); |
69 |
| - get_dockerhub_readme(dockerhub_repo, function(dockerhub_readme) { |
70 |
| - |
71 |
| - // determine if README.lite exists |
72 |
| - var readme_lite_file = 'README.lite' |
73 |
| - var readme_lite_exists = false |
74 |
| - try { |
75 |
| - if (fs.existsSync('/mnt/README.lite')) { |
76 |
| - readme_lite_file = '/mnt/README.lite'; |
77 |
| - readme_lite_exists = true |
78 |
| - } else if (fs.existsSync('/mnt/.jenkins-external/README.lite')) { |
79 |
| - readme_lite_file = '/mnt/.jenkins-external/README.lite'; |
80 |
| - readme_lite_exists = true |
81 |
| - } |
82 |
| - } catch(err) { |
83 |
| - console.log(err) |
84 |
| - } |
85 |
| - console.log(`File ${readme_lite_file} exists?: ${readme_lite_exists}.`) |
86 |
| - |
87 |
| - // if README.lite exists and github readme is too large, then use README.lite contents |
88 |
| - if (readme_lite_exists == true && github_readme.length > 25000) { |
89 |
| - console.log(`Github readme length is larger than 25000, README.lite found, using README.lite`) |
90 |
| - github_readme = fs.readFileSync(readme_lite_file).toString() |
91 |
| - } |
92 |
| - |
93 |
| - console.log(`Github readme length: ${github_readme.length}.`) |
94 |
| - console.log(`Dockerhub readme length: ${dockerhub_readme.length}.`) |
95 |
| - |
96 |
| - if (readme_lite_exists == false && github_readme.length > 25000) { |
97 |
| - throw new Error(`Github readme is longer than 25,000 characters (length ${github_readme.length}).`) |
98 |
| - } |
99 |
| - |
100 |
| - // If they dont match, update it, else, just notify console it's doing nothing. |
101 |
| - if (github_readme != dockerhub_readme) { |
102 |
| - console.log('Github readme and dockerhub full description do not match, updating...') |
103 |
| - update_dockerhub_readme(dockerhub_username, dockerhub_password, dockerhub_repo, github_readme, function() { |
104 |
| - console.log('Dockerhub updated.'); |
105 |
| - }); |
106 |
| - } else { |
107 |
| - console.log('Github readme and dockerhub full description match.') |
108 |
| - }; |
109 |
| - }); |
110 |
| - }); |
111 |
| -}; |
| 63 | + const fs = require("fs"); |
| 64 | + |
| 65 | + var dockerhub_username = process.env.DOCKERHUB_USERNAME; |
| 66 | + var dockerhub_password = process.env.DOCKERHUB_PASSWORD; |
| 67 | + |
| 68 | + var github_repo = process.env.GIT_REPOSITORY; |
| 69 | + var dockerhub_repo = process.env.DOCKER_REPOSITORY; |
| 70 | + |
| 71 | + var branch = |
| 72 | + typeof process.env.GIT_BRANCH !== "undefined" |
| 73 | + ? process.env.GIT_BRANCH |
| 74 | + : "master"; |
| 75 | + |
| 76 | + // Get github readme |
| 77 | + console.log("Getting github readme for " + github_repo); |
| 78 | + get_github_readme(github_repo, branch, function (github_readme) { |
| 79 | + // Get dockerhub full description |
| 80 | + console.log("Getting dockerhub full description for " + dockerhub_repo); |
| 81 | + get_dockerhub_readme(dockerhub_repo, function (dockerhub_readme) { |
| 82 | + // determine if README.lite exists |
| 83 | + var readme_lite_file = "README.lite"; |
| 84 | + var readme_lite_exists = false; |
| 85 | + try { |
| 86 | + if (fs.existsSync("/mnt/README.lite")) { |
| 87 | + readme_lite_file = "/mnt/README.lite"; |
| 88 | + readme_lite_exists = true; |
| 89 | + } else if (fs.existsSync("/mnt/.jenkins-external/README.lite")) { |
| 90 | + readme_lite_file = "/mnt/.jenkins-external/README.lite"; |
| 91 | + readme_lite_exists = true; |
| 92 | + } |
| 93 | + } catch (err) { |
| 94 | + console.log(err); |
| 95 | + } |
| 96 | + console.log(`File ${readme_lite_file} exists?: ${readme_lite_exists}.`); |
| 97 | + |
| 98 | + // if README.lite exists and github readme is too large, then use README.lite contents |
| 99 | + if (readme_lite_exists == true && github_readme.length > 25000) { |
| 100 | + console.log( |
| 101 | + `Github readme length is larger than 25000, README.lite found, using README.lite` |
| 102 | + ); |
| 103 | + github_readme = fs.readFileSync(readme_lite_file).toString(); |
| 104 | + } |
| 105 | + |
| 106 | + console.log(`Github readme length: ${github_readme.length}.`); |
| 107 | + console.log(`Dockerhub readme length: ${dockerhub_readme.length}.`); |
| 108 | + |
| 109 | + if (readme_lite_exists == false && github_readme.length > 25000) { |
| 110 | + throw new Error( |
| 111 | + `Github readme is longer than 25,000 characters (length ${github_readme.length}).` |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + // If they dont match, update it, else, just notify console it's doing nothing. |
| 116 | + if (github_readme != dockerhub_readme) { |
| 117 | + console.log( |
| 118 | + "Github readme and dockerhub full description do not match, updating..." |
| 119 | + ); |
| 120 | + update_dockerhub_readme( |
| 121 | + dockerhub_username, |
| 122 | + dockerhub_password, |
| 123 | + dockerhub_repo, |
| 124 | + github_readme, |
| 125 | + function () { |
| 126 | + console.log("Dockerhub updated."); |
| 127 | + } |
| 128 | + ); |
| 129 | + } else { |
| 130 | + console.log("Github readme and dockerhub full description match."); |
| 131 | + } |
| 132 | + }); |
| 133 | + }); |
| 134 | +} |
112 | 135 |
|
113 | 136 | run();
|
0 commit comments