flow-library icon indicating copy to clipboard operation
flow-library copied to clipboard

Is the assumption of a master branch prehaps incorrect?

Open gorenje opened this issue 8 months ago • 3 comments

I was looking at this code - is the assumption of master to be the main branch or even a branch perhaps no longer applicable?

gorenje avatar Oct 06 '23 10:10 gorenje

Indeed - this was a quick hack to remap urls when 99.9% would have a master branch.

Any suggestions for improvements to figure out the right url for these assets would be welcome.

knolleary avatar Oct 06 '23 10:10 knolleary

The background to me reading that code was/is trying to figure out why my readmes aren't being shown @ flows.nodered.org - e.g. this package

What I believe I should be doing is having a homepage value in package.json that points to a valid README.md ... now if that is the case, then I would remove the guestimations on where a README could be (i.e. using branch names) and just update the documentation to point that out.

And additionally add an error message to the blank package page @ flows.nodered.org saying: "add valid markdown readme to homepage link".

EDIT: readme works fine at npmjs.com - hence there is a readme but its not showing @ flows.nodered.org - why I wonder!

gorenje avatar Oct 06 '23 10:10 gorenje

btw the api from gh can be used without token e.g. https://api.github.com/repos/gorenje/cdn.openmindmap.org/branches?per_page=10 - so that's one more request to get the branches for a repo. I guess from there one can look for either main or master or banana!

EDIT: An example of how to do this is shown by this flow:

[{"id":"b52e45acc8a9f7bf","type":"inject","z":"baed6b80d48bcdff","name":"inject repo details","props":[{"p":"repo","v":"node-red-contrib-nodedev","vt":"str"},{"p":"owner","v":"gorenje","vt":"str"},{"p":"possible_branch_names","v":"[\"master\",\"main\",\"banana\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":636,"y":192,"wires":[["cc3f16463657ca29"]]},{"id":"cc3f16463657ca29","type":"change","z":"baed6b80d48bcdff","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.github.com/repos/\" & $$.owner & \"/\" & $$.repo & \"/branches?per_page=100\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":721,"y":552,"wires":[["9af3d8c5d4c9df6b"]]},{"id":"b6a2d74bf6cb3292","type":"json","z":"baed6b80d48bcdff","name":"","property":"payload","action":"","pretty":false,"x":641,"y":661.5,"wires":[["0e50bfc559b5a52c"]]},{"id":"f0b9aba776bd08e7","type":"change","z":"baed6b80d48bcdff","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.github.com/repos/\" & $$.owner & \"/\" & $$.repo & \"/git/trees/\"  & $$.payload[0].commit.sha","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1419,"y":661.5,"wires":[["dc6e303268c01ce3"]]},{"id":"14078aea0a8bae7e","type":"debug","z":"baed6b80d48bcdff","name":"readme content","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1703,"y":1291,"wires":[]},{"id":"86fc23b5feb61fc9","type":"json","z":"baed6b80d48bcdff","name":"","property":"payload","action":"","pretty":false,"x":643,"y":773.5,"wires":[["158845c805ee8d81"]]},{"id":"158845c805ee8d81","type":"function","z":"baed6b80d48bcdff","name":"find a readme in the tree","func":"msg.payload = msg.payload.tree.filter( (d) => {\n    return d.path.match(/^readme/i) \n})\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":897,"y":773.5,"wires":[["d680788fc8d83f31"]]},{"id":"d680788fc8d83f31","type":"switch","z":"baed6b80d48bcdff","name":"ensure payload has at least 1 entry","property":"payload.length","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1210,"y":773.5,"wires":[["1377eab9db09b540"]]},{"id":"1377eab9db09b540","type":"change","z":"baed6b80d48bcdff","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload[0].url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1459,"y":773.5,"wires":[["b8f534d3b4b453f4"]]},{"id":"39864d5d359d76bb","type":"json","z":"baed6b80d48bcdff","name":"","property":"payload","action":"","pretty":false,"x":662,"y":1003.5,"wires":[["2c940b80d25f6b24"]]},{"id":"2c940b80d25f6b24","type":"change","z":"baed6b80d48bcdff","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":945,"y":1003.5,"wires":[["dc4d7f88f34b20eb"]]},{"id":"dc4d7f88f34b20eb","type":"function","z":"baed6b80d48bcdff","name":"correct base64 decoding","func":"msg.payload = Buffer.from(msg.payload, 'base64').toString('utf8')\n\nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1288,"y":1003.5,"wires":[["14078aea0a8bae7e"]]},{"id":"0e50bfc559b5a52c","type":"function","z":"baed6b80d48bcdff","name":"filter branch names","func":"msg.payload = msg.payload.filter( (d) => {\n    return msg.possible_branch_names.indexOf( d.name ) > -1\n})\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":661.5,"wires":[["1002c90f7e39dd44"]]},{"id":"1002c90f7e39dd44","type":"switch","z":"baed6b80d48bcdff","name":"ensure payload has at least 1 entry","property":"payload.length","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1163,"y":661.5,"wires":[["f0b9aba776bd08e7"]]},{"id":"c9c6ed8e2be8e039","type":"group","z":"baed6b80d48bcdff","name":"3 http requests","style":{"label":true},"nodes":["9af3d8c5d4c9df6b","dc6e303268c01ce3","b8f534d3b4b453f4"],"x":1679,"y":511,"w":210,"h":303.5},{"id":"9af3d8c5d4c9df6b","type":"http request","z":"baed6b80d48bcdff","g":"c9c6ed8e2be8e039","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1775,"y":552,"wires":[["b6a2d74bf6cb3292"]]},{"id":"dc6e303268c01ce3","type":"http request","z":"baed6b80d48bcdff","g":"c9c6ed8e2be8e039","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","persist":false,"insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1785,"y":661.5,"wires":[["86fc23b5feb61fc9"]]},{"id":"b8f534d3b4b453f4","type":"http request","z":"baed6b80d48bcdff","g":"c9c6ed8e2be8e039","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","persist":false,"insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1793,"y":773.5,"wires":[["39864d5d359d76bb"]]}]

It takes a repo as input and gives back the contents of the readme. It finds a branch and readme file and returns the content of the first found.

gorenje avatar Oct 06 '23 13:10 gorenje