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

[FEATURE] automate branch and commit hash CLI options #207

Closed
mdjastrzebski opened this issue Oct 3, 2022 · 8 comments
Closed

[FEATURE] automate branch and commit hash CLI options #207

mdjastrzebski opened this issue Oct 3, 2022 · 8 comments
Assignees
Labels
CLI feature good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@mdjastrzebski
Copy link
Member

Is your feature request related to a problem? Please describe.

Automatically detect branch name and commit hash when reassure detects that it is run inside a Git repo.

Describe the solution you'd like

Basically make current --branch $(git branch --show-current) --commitHash $(git rev-parse HEAD) options automatic when user is using Git.
Kept the existing CLI options to allow user to override the default values and/or support other source controls systems.
Invoke git binary commands using node child_process(?) API to avoid external deps.

Describe alternatives you've considered

  • Instead of invoking external binary use some node package like simple-git to communicate with GIT repo.

Additional context

@ShaswatPrabhat
Copy link
Contributor

ShaswatPrabhat commented Oct 4, 2022

Picking this up please.

Will it be a good idea to keep these values as default in measure.ts after auto detecting git based branches ?

@mdjastrzebski
Copy link
Member Author

@ShaswatPrabhat Thanks for working on this. I'm not sure I understand your question though.

The data flow between the packages should be the same as is now for branch and commit-hash CLI options. The difference should be that when Reassure 'measure' command does not receive either branch or commit-hash option then it tries to get the missing value(s) from Git if possible.

@mdjastrzebski
Copy link
Member Author

A good place for checking these values is the very beginning of "run" method in measure.ts in CLI package

@ShaswatPrabhat
Copy link
Contributor

@mdjastrzebski there were a couple of things I wanted to check:

  • Which way of spawning a child process would be preferable ? Right now I am looking at child_process.fork, but any notes regarding the same?
  • With the above approach the function becomes an IIFE like so:
  const simpleGit = require('simple-git');
  const git = simpleGit({ baseDir: process.cwd() });
  const branch = await git.revparse(['--abbrev-ref', 'HEAD']);
  const commitHash = await git.revparse(['HEAD']);
  process.send({ branch, commitHash });
})();

Please let me know if this is what you had thought of

@mdjastrzebski
Copy link
Member Author

I've looked more into the simple-git package. It seems that it's actually invoking git binary by itself, so we can give it a try.

@ShaswatPrabhat
Copy link
Contributor

ShaswatPrabhat commented Oct 4, 2022

This is how it is shaping up @mdjastrzebski .

Not very happy with the IIFE .

Can we not have a simple await based function call immediately in run() method ? Do we need a fork at all

@ShaswatPrabhat
Copy link
Contributor

And an alternative way

@mdjastrzebski
Copy link
Member Author

Resolved by #211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI feature good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants