update / updater-contributors

Update the contributors array in package.json with the contributors returned by the GitHub API.
MIT License
3 stars 0 forks source link

fails for Mocha #3

Open boneskull opened 7 years ago

boneskull commented 7 years ago

Wanted to get this into our publishing workflow, but ran into varied difficulties.

First problem is that there's something weird going on in either repo-utils, expand-pkg, or parse-git-config. Was trying to fix this, but once parse-git-config giving me problems, I crawled back out of the rabbit hole.

To reproduce badness:

  1. execute npm install -g update update-contributors
  2. execute update init, choose contributors
  3. execute update in mocha working copy
  4. result:
boneskull@lectroid /Volumes/alien/mochajs/mocha                                               [21:19:53]
> $ update                                                                           ⬡ 7.1.0 [±master ✓]
[21:19:59] using file ~/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/lib/updatefile.js
[21:19:59] starting update.contributors
[21:19:59] starting update.contributors:default task
[21:19:59] ✔ running: contributors
[21:19:59] starting update.contributors:authenticate task
[21:19:59] finished update.contributors:authenticate task 3ms
TypeError: Cannot read property 'split' of undefined
    at Object.repo.expandUrl (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/repo-utils/index.js:432:24)
    at Schema.module.exports (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/expand-pkg/lib/expanders/git.js:9:36)
    at Schema.normalizeField (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/map-schema/index.js:557:16)
    at Schema.update (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/map-schema/index.js:246:8)
    at Schema.module.exports (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/expand-pkg/lib/expanders/owner.js:14:10)
    at Schema.normalizeField (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/map-schema/index.js:557:16)
    at Schema.normalize (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/map-schema/index.js:497:27)
    at Config.expand (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/expand-pkg/index.js:103:22)
    at Pkg.<anonymous> (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/update/node_modules/base-pkg/index.js:55:27)
    at Task.fn (/Users/boneskull/.nvm/versions/node/v7.1.0/lib/node_modules/updater-contributors/updatefile.js:23:24)

Mocha's package.json has a string homepage value and an object repository value.

I tracked the problem to the weirdness happening in lib/expanders/git.js of expand-pkg:

module.exports = function(val, key, config, schema) {
  if (utils.isString(config.repository)) {
    utils.merge(config, utils.repo.expandUrl(config.homepage, config));
  }
  // snip
};

I'm not sure why we're looking at config.repository and then expanding config.homepage. The intent of this function is unclear. To convince myself I was sane, I created a failing test:

 it('should use the given homepage if repository.url is present', function() {
   var pkg = {
     homepage: 'https://github.com/jonschlinkert/test-project',
     repository: 'git://github.com/jonschlinkert/test-project.git'
   };
   var res = config.expand(pkg);
   assert(res.homepage);
   assert(res.homepage, 'https://github.com/jonschlinkert/test-project');
});

Anyhow, there were a bunch of other failing tests here, because of problems in parse-git-config and its ilk. Here are some:

  1) expand-pkg (no git repository) owner should get owner from the git url:

      AssertionError: 'Christopher%20Hiller' == 'Christopher Hiller'
      + expected - actual

      -Christopher%20Hiller
      +Christopher Hiller

      at Context.<anonymous> (test/test-no-git.js:271:14)

  2) expand (no package.json) homepage should add a homepage from git repository:

      AssertionError: 'https://github.com/Christopher%20Hiller/project-no-package' == 'https://github.com/jonschlinkert/project-no-package'
      + expected - actual

      -https://github.com/Christopher%20Hiller/project-no-package
      +https://github.com/jonschlinkert/project-no-package

      at Context.<anonymous> (test/test-no-package.js:275:14)
      at test/test-no-package.js:256:9
      at node_modules/gitty/lib/repository.js:529:5
      at ChildProcess.exithandler (child_process.js:202:7)
      at maybeClose (internal/child_process.js:885:16)
      at Socket.<anonymous> (internal/child_process.js:334:11)
      at Pipe._handle.close [as _onclose] (net.js:501:12)

  3) expand (no package.json) homepage should add repository when setting hompage:

      AssertionError: 'Christopher%20Hiller/project-no-package' == 'jonschlinkert/project-no-package'
      + expected - actual

      -Christopher%20Hiller/project-no-package
      +jonschlinkert/project-no-package

      at Context.<anonymous> (test/test-no-package.js:281:14)
      at test/test-no-package.js:256:9
      at node_modules/gitty/lib/repository.js:529:5
      at ChildProcess.exithandler (child_process.js:202:7)
      at maybeClose (internal/child_process.js:885:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

FWIW, this is my .gitconfig. If the format is invalid, Git is not complaining about it.

This is where I gave up and decided to tell you about it. :smile:

Anyway, once I disabled the weirdness caused by expand-pkg's lib/expanders/git.js, I got some contributors:

{
  "contributors": [
    "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
    "Christopher Hiller <boneskull@boneskull.com> (https://boneskull.com)",
    "Travis Jeffery <tj@travisjeffery.com> (https://twitter.com/travisjeffery)",
    "Daniel St. Jules <danielst.jules@gmail.com> (http://danielstjules.com)",
    "David da Silva <yo@dasilvacont.in> (http://dasilvacont.in)",
    "Guillermo Rauch <rauchg@gmail.com> (http://twitter.com/rauchg)",
    "Ariel Mashraki <ariel@mashraki.co.il> (https://twitter.com/arielmashraki)",
    "Attila Domokos (http://www.adomokos.com)",
    "John Firebaugh (https://github.com/jfirebaugh)",
    "Nathan Houle <nathan+github@nathanhoule.com> (http://nathanhoule.com)",
    "Jo Liss <joliss42@gmail.com> (https://twitter.com/jo_liss)",
    "(https://github.com/jugglinmike)",
    "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io)",
    "Brendan Nee <brendan@blinktag.com> (http://blinktag.com)",
    "Glen Mailer <glen@stainlessed.co.uk> (http://stainlessed.co.uk)",
    "James Carr <james.r.carr@gmail.com> (http://blog.james-carr.org)",
    "Domenic Denicola <d@domenic.me> (https://domenic.me)",
    "Scott Santucci <ScottFreeCode@gmail.com> (https://ScottFreeCode.github.io)",
    "Aaron Heckmann <aaron.heckmann+github@gmail.com> (http://twitter.com/aaronheckmann)",
    "Mislav Marohnić <mislav.marohnic@gmail.com> (http://mislav.net)",
    "Peter Müller <munter@fumle.dk> (https://mntr.dk)",
    "Ryunosuke Sato <tricknotes.rs@gmail.com> (http://tricknotes.hateblo.jp)",
    "Kazuhito Hokamura (http://webtech-walker.com)",
    "Forbes Lindesay (http://www.forbeslindesay.co.uk)",
    "jongleberry <me@jongleberry.com> (twitter.com/jongleberry)",
    "Joshua Krall <joshuakrall@pobox.com> (https://github.com/jkrall)",
    "Maximilian Antoni <mail@maxantoni.de> (http://maxantoni.de)",
    "Jake Verbaten <raynos2@gmail.com> (http://github.com/Raynos)",
    "Xavier Antoviaque <xavier@opencraft.com> (http://antoviaque.org)",
    "Andreas Lind <andreas@one.com> (https://github.com/papandreou)",
    "Ben Bradley (https://github.com/ben-bradley/resume)",
    "Benjie Gillam (http://www.benjiegillam.com)",
    "Cory Thomas (https://github.com/dump247)",
    "Fredrik Enestad <fredrik.enestad@soundtrackyourbrand.com> (http://soundtrackyourbrand.com)",
    "(https://github.com/jldailey)",
    "Merrick Christensen <merrick.christensen@gmail.com> (http://www.merrickchristensen.com)",
    "Michael Demmer (https://github.com/demmer)",
    "Nathan Bowser <nbowser@gmail.com> (nathanbowser.com)",
    "Paul Miller <paul+gh@paulmillr.com> (paulmillr.com)",
    "Rico Sta. Cruz <hi@ricostacruz.com> (http://ricostacruz.com)",
    "Sindre Sorhus <sindresorhus@gmail.com> (https://twitter.com/sindresorhus)",
    "Sune Simonsen <sune@we-knowhow.dk> (https://github.com/sunesimonsen)",
    "Tyson Mote <tyson@bufio.net> (http://stovepipestudios.com)",
    "Valentin Agachi (http://agachi.name)",
    "Wil Moore III <wil.moore@wilmoore.com> (http://wilmoore.com)",
    "eiji.ienaga (http://friendfeed.com/haru01)",
    "Zhouxuan Yang <fool2fish@gmail.com> (http://fool2fish.cn)",
    "Adam Gruber (https://github.com/adamgruber)",
    "Alex Early (http://aeflash.com)",
    "Arian Stolwijk <stolwijk.arian@gmail.com> (http://www.aryweb.nl)",
    "Avi Vahl (https://github.com/AviVahl)",
    "",
    "Brian Beck <exogen@gmail.com> (http://brianbeck.com)",
    "Buck Doyle (https://github.com/backspace)",
    "Christian (http://www.rndm.de)",
    "",
    "",
    "Ian Storm Taylor (http://ianstormtaylor.com)",
    "",
    "Jacob Wejendorp (http://dorp.io)",
    "James Nylen <jnylen@gmail.com> (https://about.me/jnylen)",
    "John Reeves (http://jonnyreeves.co.uk)",
    "",
    "",
    "Konstantin Käfer <mail@kkaefer.com> (https://kkaefer.com)",
    "Long Ho <holevietlong@gmail.com> (https://medium.com/@longho)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Simon Gaeremynck (http://www.gaeremynck.com)",
    "",
    "",
    "",
    "",
    "Xavier Damman <xdamman@gmail.com> (http://xdamman.com)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "(https://github.com/aaroncrows)",
    "",
    "",
    "",
    "",
    "Andrew Nesbitt <andrewnez@gmail.com> (http://nesbitt.io)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Benoit Larroque (https://github.com/zetaben)",
    "",
    "",
    "Berker Peksag <berker.peksag@gmail.com> (http://berkerpeksag.com)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Charles Lowell <cowboyd@frontside.io> (http://frontside.io)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Dominic Barnes <dominic@dbarnes.info> (http://dbarnes.info)",
    "Douglas Wilson <doug@somethingdoug.com> (https://github.com/dougwilson)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Greg Perkins <gregperkins@alum.mit.edu> (https://twitter.com/gregrperkins)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "James Lal <james@lightsofapollo.com> (http://blog.lightsofapollo.com)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Jeremy Martin (https://twitter.com/jmar777)",
    "",
    "João Moreno (http://resume.joaomoreno.com)",
    "Joey Cozza <joeycozza@gmail.com> (https://github.com/joeycozza)",
    "John Doty <jrhdoty@gmail.com> (https://github.com/jrhdoty)",
    "",
    "Jonas Dohse (https://github.com/dohse)",
    "(https://github.com/jcreamer898)",
    "",
    "",
    "Jordan Sexton <jordan@jordansexton.com> (http://jordansexton.com)",
    "Josh Eversmann (https://github.com/jeversmann)",
    "Josh Lory (https://github.com/joshlory)",
    "Julien Wajsberg (http://everlong.org)",
    "",
    "",
    "",
    "Keith Cirkel (https://www.keithcirkel.co.uk)",
    "Kent C. Dodds <kent+github@doddsfamily.us> (https://kentcdodds.com)",
    "Kevin Burke <kev@inburke.com> (https://kev.inburke.com)",
    "Kevin Conway <kevinjacobconway@gmail.com> (https://github.com/kevinconway)",
    "Kevin Kirsche <Kev.Kirsche@gmail.com> (https://kevinkirsche.com)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "Mal Graty (https://github.com/mal)",
    "Marc Kuo <marc@routific.com> (https://routific.com)",
    "Marcello Bastéa-Forte <marcello@cellosoft.com> (http://marcello.cellosoft.com)",
    "",
    "",
    "",
    "",
    "",
    "Matthew Shanley <matthewshanley@littlesecretsrecords.com> (http://littlesecretsrecords.com)",
    "(https://github.com/mattias-lw)",
    "Michael Jackson <mjijackson@gmail.com> (http://mjackson.me)",
    "Mike Olson (http://mwolson.org)",
    "",
    "",
    "Michal Charemza (http://charemza.name)",
    "Mick Brooks (http://sinking.in/blog)",
    "Nathan Black <nathan@nathanblack.org> (http://nathanblack.org)",
    "",
    "",
    "olegtsyba <oleg.tsyba.ua@gmail.com> (https://github.com/olegabyst)",
    "",
    "",
    "Pete Hawkins (http://phawk.co.uk)",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
  ]
}

You can see the current values here.

  1. The contributors should be sorted alphabetically instead of by contribution, which should eliminate most (not all) modifications to this value, and instead only generate additions.
  2. The homepage should fallback to the user's GitHub profile.
  3. The GitHub profile name should be used in lieu of a real name.
jonschlinkert commented 7 years ago

so sorry for the late reply, I was out with a bad cold for a couple of weeks. I'll address this ASAP. thanks for the issue

edit: btw, thanks for the suggestions as well. We'll make those changes. It's awesome that you're looking to use this with mocha, I'm sorry I wasn't able to get this taken care of faster.

boneskull commented 7 years ago

no rush; I'm well-acquainted with providing free support and bug fixes for software :smile:

doowb commented 7 years ago

@boneskull I updated expand-pkg to use the repository property instead of homepage. Thanks for digging into the code to get to that point.

The error should be gone if you reinstall and run update again.

I'll leave this open to address the other suggestions. We'll probably create individual issues around those and then we can close this issue.