question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Git Utils fileMatch API design

See original GitHub issue

Looks like a core bit of the git util functionality was removed with a refactor.

https://github.com/netlify/build/blame/master/packages/git-utils/README.md#L48-L53

The fileMatch function should return a function that

Original code:

const micromatch = require('micromatch')
const mapValues = require('lodash.mapvalues')

const isExclude = p => p.startsWith('!')

module.exports = function fileMatcher(keyedPaths) {
  function matchPatterns(patterns) {
    return mapValues(keyedPaths, paths => {
      const excludePatterns = patterns.filter(p => isExclude(p))
      const includePatterns = patterns.filter(p => !isExclude(p))
      const included = includePatterns.reduce((accum, pattern) => accum.concat(micromatch.match(paths, pattern)), [])
      return excludePatterns.reduce((accum, pattern) => micromatch.match(accum, pattern), included)
    })
  }
  function finalize(keyedPaths) {
    return Object.assign(
      Object.assign(
        {},
        mapValues(keyedPaths, paths => paths.length > 0),
      ),
      { getKeyedPaths: () => keyedPaths },
    )
  }
  return (...patterns) => finalize(matchPatterns(patterns))
}

getKeyedPaths returns an object that looks like:

{ 
  modified: [ 'example.js', 'src/LocalGit.js' ],
  created: [ 'src/index.js' ],
  deleted: [ 'src/git/_tests/local_dangerfile_example.js' ],
  edited: [ 'example.js',  'src/index.js' ] 
}

This is quite important for advanced diffing functionality.

Can we please get this back in

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
jlengstorfcommented, Jan 18, 2020

I think I prefer option 2 as well

the keys could return false as well if no files come back, which would further simplify usage:

const cssFiles = git.fileMatch('**/*.css');

if (!cssFiles.editedFiles) return;

// do stuff

I think there’s also an argument to drop the *Files part for keys; I’m not sure it adds additional clarity vs:

const cssFiles = git.fileMatch('**/*.css');

if (!cssFiles.edited) return;

if (cssFiles.edited.includes('just-changed.css')) {
  // do stuff
}
0reactions
ehmickycommented, Jan 23, 2020

Done at #722.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the danger.danger.git function in danger
To help you get started, we've selected a few danger.danger.git examples, based on popular ... if (jsAppFiles.length) { const listed = danger.github.utils.
Read more >
Make Git Your API
This post describes your options and introduces fusebit/cloud-git, a pure JavaScript git server implementation for Node.js that lets you easily ...
Read more >
What programming language is GitHub written in?
The language to learn depends on a number of things. Apple has swift and objectivec. They are integrate with the apple iOS sdk...
Read more >
GitHub REST API Tutorial - REST API Support In GitHub
This GitHub Tutorial will explain how to use REST API for various ... have been useful for automating various scenarios for different tools....
Read more >
Yaml schema validation golang - cittafamiglia.it
If you are looking for a more reproducible way, design your entities and create ... Under Jobs , click the Explore-GitHub-Actions job. xml...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found