Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

Add GitHub auto-updater#33

Open
jman294 wants to merge 1 commit into
cdnjs:masterfrom
jman294:master
Open

Add GitHub auto-updater#33
jman294 wants to merge 1 commit into
cdnjs:masterfrom
jman294:master

Conversation

@jman294

@jman294 jman294 commented Apr 27, 2018

Copy link
Copy Markdown

The git updater without cloning individual repositories.

@jman294 jman294 mentioned this pull request Apr 27, 2018

@PeterDaveHello PeterDaveHello left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jman294 thanks for the PR, please squash the commits into a single one first, thanks!

Comment thread updaters/git.js Outdated

var update = function(library, callback) {
var target = library.autoupdate.target;
console.log(target)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should git auto-update be touched here?

@PeterDaveHello PeterDaveHello left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the user-agent in a single place?

Comment thread updaters/github.js Outdated
var update = function(library, callback) {
async.series([
function(next) {
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give + spaces between and after it

Comment thread updaters/github.js Outdated
function(next) {
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags',
headers: {
'User-Agent': 'cdnjs'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say CDNJS GitHub auto-updater

Comment thread updaters/github.js Outdated
var basePath = library.autoupdate.basePath || "";
var allFiles = [];

rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give + spaces between and after it

Comment thread updaters/github.js Outdated

rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1',
headers: {
'User-Agent': 'cdnjs'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say CDNJS GitHub auto-updater

Comment thread updaters/github.js Outdated
fs.writeFileSync(libraryPath, JSON.stringify(libraryJSON, undefined, 2) + '\n');
}
async.each(allFiles, function(file, callback) {
//var fileName = path.relative(path.join(localTarget, file.basePath), file._);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed?

@jman294

jman294 commented Apr 27, 2018

Copy link
Copy Markdown
Author

Sorry for somewhat unprofessional style, squashed all commits into one (I believe).

Comment thread .gitignore Outdated
tmp
git_repo_local_cache/

*.swp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't update .gitignore in this PR, it's not related. I also suggest to include it in your personal global gitignore list, like:
https://github.com/PeterDaveHello/Unitial/blob/master/gitignore_global#L2
https://github.com/PeterDaveHello/Unitial/blob/master/gitconfig#L72

Comment thread updaters/github.js Outdated
};

var githubRepo = function (url) {
return url.slice(url.indexOf('/', 10)+1, url.indexOf('.git'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces for +

@jman294 jman294 Apr 28, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other stylistic changes required? I am happy to make all changes, I just am not aware of your style guidelines. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should copy this one here: https://github.com/cdnjs/cdnjs/blob/master/.jscsrc
We have an issue with it: #12
Thanks for asking!

Comment thread updaters/github.js Outdated
.then(function (jsonString) {
var filesJson = JSON.parse(jsonString);
_.each(library.autoupdate.fileMap, function(mapGroup) {
var cBasePath = mapGroup.basePath || "", files = [];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use single quotes here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet you're right!

Comment thread updaters/github.js Outdated
rp({
uri:'https://raw.githubusercontent.com/'
+ githubRepo(library.autoupdate.target) + '/'
+ file.tree + '/' + file.basePath + '/' + fileName,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change this to path.normalize(path.join(file.tree, file.basePath, fileName)),

This is a path for a website, but I think the benefit still applies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@PeterDaveHello

Copy link
Copy Markdown
Contributor

Hi @jman294! I've added Travis CI to help check coding style issues, hope it'll help us save time on style issues, please take a look, thank you! 😄

Download correct tarballs

Add file retrieval functionality

Fix up github updater

Delete .cdnjs.js.swp

Delete .git.js.swp

Delete .autoupdate.js.swp

Fixed up style

Issue 27 GitHub Updater

Add space after +

Github Updater

Fix style
@jman294

jman294 commented May 1, 2018

Copy link
Copy Markdown
Author

Is there anything that needs to happen for this pull request to complete? I have tested the updater to the best of my ability.

@PeterDaveHello PeterDaveHello left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to invite @extend1994 & @sufuf3 join the review and test here.

@PeterDaveHello PeterDaveHello changed the title Github Updater Add GitHub Updater May 3, 2018
@PeterDaveHello PeterDaveHello changed the title Add GitHub Updater Add GitHub auto-updater May 3, 2018
@extend1994

Copy link
Copy Markdown

Review in progress, might need some more time.

@extend1994 extend1994 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this PR can't be used to get the assets in the release page which #27 hopes to achieve?
The used GitHub API in this PR is to get files in a Git repository, #27 wants us to use https://developer.github.com/v3/repos/releases/#releases in my view.

Comment thread updaters/github.js
});

var needed = _.filter(versions, function (version) {
var tagName = versions[0].version;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version.version[0] should be the one to retrieve a tag name :)

Comment thread updaters/github.js
var needed = _.filter(versions, function (version) {
var tagName = versions[0].version;
if ((tagName === 'v' || tagName === 'V' || tagName === 'r') &&
version.length > 1 && !isNaN(version[1])) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we want to check version length and numberic version, so it would be version.version.length > 1 && !isNaN(version.version[1])according to your version object.

Comment thread updaters/github.js
_.each(mapGroup.files, function (cRule) {
var newFiles = [];
for (var file of filesJson.tree) {
if (file.path.indexOf(cBasePath) === 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add && file.type !== "tree" here in order to prevent directory match like what option nodir: true can do in glob library.

Comment thread updaters/github.js
if (minimatch(file.path, cRule, {
nodir: true,
realpath: true
})) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove nodir and realpath option, they are only for glob lib and there has no effect in minimatch lib.
Then the code block here can be simpler:

if (minimatch(file.path, cRule)) {
  newFiles.push({ path: file.path, tree: fullData.tree });
}

Comment thread updaters/github.js
rp({
uri: 'https://raw.githubusercontent.com/'
+ githubRepo(library.autoupdate.target) + '/'
+ path.normalize(path.join(file.tree, file.basePath, fileName)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.normalize(path.join(file.tree, fileName) is enough, fileName has included basePath.

Comment thread updaters/github.js
var fileName = file._;
var fileTarget = path.normalize(
path.join(__dirname, '../../cdnjs', 'ajax',
'libs', library.name, tag, fileName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName here should be path.relative(file.basePath, fileName);,
I suppose a better way is to replace it with a local and meaningful variable
(instead of using path.relative(file.basePath, fileName); directly)
e.g. Add

var localFileName = path.relative(file.basePath, file._);

under fileName declaration. And use it to replace fileName.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants