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

feat(cli): cli interface #53

Merged
merged 7 commits into from Jul 31, 2020

Conversation

TomKristie
Copy link
Contributor

Create a CLI interface to interact with the framework-core
It:

  • takes arguments and maps them to user PR options
  • takes a git directory and generates a change set Map from the git diff items
  • initializes octokit and a logger
  • invokes framework-core
  • includes core-logic testing

Closes #35

Redo of #51

@TomKristie TomKristie requested a review from a team as a code owner July 30, 2020 22:00
@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #53 into master will decrease coverage by 11.05%.
The diff coverage is 63.06%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #53       +/-   ##
===========================================
- Coverage   96.32%   85.26%   -11.06%     
===========================================
  Files          11       14        +3     
  Lines         761     1140      +379     
  Branches       47       71       +24     
===========================================
+ Hits          733      972      +239     
- Misses         27      167      +140     
  Partials        1        1               
Impacted Files Coverage Δ
src/bin/code-suggester.ts 0.00% <0.00%> (ø)
src/bin/handle-git-dir-change.ts 85.52% <85.52%> (ø)
src/bin/workflow.ts 96.15% <96.15%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1f69e2...36b115f. Read the comment docs.

Copy link
Contributor

@chingor13 chingor13 left a comment

Choose a reason for hiding this comment

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

What happens if the git command is not available? We should probably have a nicer error message.

src/bin/code-suggester.ts Outdated Show resolved Hide resolved
* @param {string} dir the wildcard directory containing git change, not necessarily the root git directory
* @returns {string} the absolute path relative to the path that the user executed the bash command in
*/
export function resolvePath(dir: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function doesn't seem to be adding much, any reason we shouldn't just use path.resolve wherever this is being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I separated it out so that I can explicitly test that absolute paths are generated the way I want to.

src/bin/handle-git-dir-change.ts Outdated Show resolved Hide resolved
src/bin/handle-git-dir-change.ts Outdated Show resolved Hide resolved
src/bin/handle-git-dir-change.ts Outdated Show resolved Hide resolved
@TomKristie
Copy link
Contributor Author

I added an explicit git installation check which I didn't test since I consider that an integration test which is outside of scope. Let me know what you think! @chingor13

src/bin/handle-git-dir-change.ts Outdated Show resolved Hide resolved
src/bin/handle-git-dir-change.ts Show resolved Hide resolved
* @param dir the directory containing git changes
* @returns {Promise<Changes>} the change set
*/
export function getChanges(dir: string): Promise<Changes> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export function getChanges(dir: string): Promise<Changes> {
export async function getChanges(dir: string): Promise<Changes> {

Should this be marked async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily. It's only required when we have an await statement.

src/bin/workflow.ts Outdated Show resolved Hide resolved
gitRootDir: string,
gitDiffPattern: string
): Promise<GitFileData> {
return new Promise((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would async/await be easier here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt it was easier to explicitly be able to get the readfile error for clearer error messaging. Otherwise I'd have to have nested try catch blocks if i wanted more precise error logging.

test/fixtures/fixtures Outdated Show resolved Hide resolved
// tslint:disable:no-unused-expression
// .null triggers ts-lint failure, but is valid chai
// .true triggers ts-lint failure, but is valid chai
describe('git directory diff output to git file data + content', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: usually the describe block shows the function name under test

Suggested change
describe('git directory diff output to git file data + content', () => {
describe('getGitFileData', () => {

* @returns {string} the absolute path relative to the path that the user executed the bash command in
*/
export function resolvePath(dir: string) {
const absoluteDir = path.resolve(process.cwd(), dir);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is only used for the CLI then implicitly depending on the cwd may be ok. If this will be included later in the core (which I could potentially see), we instead want the relative root to be explicit (and provided by the caller - e.g. the CLI).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is explicitly for the CLI. I've intended the bin directory to be strictly for the CLI. If we want to do work for the framework-core it will not be handled here. It is a small function so if we wanted to have similar behaviour in the framework-core it might make more sense to duplicate the work.

TomKristie and others added 3 commits July 31, 2020 16:07
Co-authored-by: Jeff Ching <chingor@google.com>
@chingor13 chingor13 requested a review from a team July 31, 2020 22:01
@TomKristie TomKristie merged commit 836e0bc into googleapis:master Jul 31, 2020
@TomKristie TomKristie deleted the cli-interface-feat branch July 31, 2020 22:13
@TomKristie TomKristie linked an issue Aug 4, 2020 that may be closed by this pull request
2 tasks
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 this pull request may close these issues.

Create a CLI to wrap the framework-core Support non-"master" default primary branch
2 participants