Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto fix conflicts in certain files #196

Closed
spalger opened this issue May 11, 2020 · 1 comment · Fixed by #206
Closed

Auto fix conflicts in certain files #196

spalger opened this issue May 11, 2020 · 1 comment · Fixed by #206

Comments

@spalger
Copy link
Contributor

spalger commented May 11, 2020

In the Kibana repo specifically there are a handful of files which regularly experience conflicts that could be fixed automatically if we knew that conflicts were limited to a specific set of files. I wonder if we could define a module which would be loaded to inspect the conflicting files to decide if the conflicts could be fixed automatically?

Something like this perhaps?

require('backport').run({
  async autoFixConflicts(files, directory, log) {
	const candidates = [
      'yarn.lock',
      'packages/kbn-pm/dist/index.js'
    ]

	const noCandidates = files.every(f => !candidates.includes(f))
	if (noCandidates) {
      log.info('conflicts are not in auto fixable files')
      return false;
    }

    const nonCandidates = files.filter(f => !candidates.includes(f))
	if (nonCandidates.length) {
      log.info('unable to auto fix conflicts because of changes in', nonCandidates.join(', '))
      return false;
    }

    await execa('git', ['checkout', '--', ...files], { cwd: directory })

    log.info('bootstrapping backport repo')
    await execa('yarn', ['kbn', 'bootstrap'], { cwd: directory })

    if (files.includes('packages/kbn-pm/dist/index.js')) {
      log.info('auto fixing kbn/pm dist')
      await execa('yarn', ['kbn', 'run', 'build', '-i', '@kbn/pm'], { cwd: directory })
    }

    return true;
  }
})
@sorenlouv
Copy link
Owner

sorenlouv commented May 11, 2020

We could definitely do something like that. I've been considering converting the .backportrc.json config to a javascript file (.backportrc.js) to support dynamic stuff like this.

{
  upstream: 'elastic/kibana',
  branches: ['7.x', '7.8', '7.7', '...'],
  onConflict: async (files, directory, log) { // ... }
}

But it would probably be easier to start with the approach you suggest. Then I think all options should be configurable that way:

require("backport").run({
  upstream: 'elastic/kibana',
  branches: ['7.x', '7.8', '7.7', '...'],
  onConflict: async (files, directory, log) { // ... }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants