Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AliabbasMerchant
Copy link
Contributor

Fixes #956
Replaces #986

I finally figured out how to do this 🥳

(Have organised commits logically, so reviewing commit-wise should be fairly easy; Also, have tried to make sure that there are no breaking changes at any commit)
The first 6 commits are just the prerequisites
The 7th commit contains the sample interactive template selection test

Requesting reviews, especially from @vilmibm and @mislav
(I don't have permissions to request a review via GitHub directly, hence tagging you all 😅 )

Comment on lines +72 to +75
RunE: func(c *cobra.Command, args []string) error {
templateHandler := githubtemplate.GitHubTemplateHandler
return issueCreate(c, args, &templateHandler)
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, We can use this trick to stub anything.
No need to create extra command-specific structs, and build them here and pass them to the command, to be read there.
All that is internally handled by cobra here.

return &cmdOutStreams, err
}

func PrepareCommandArguments(command string) (*cobra.Command, []string, *cmdOut, func(), error) {
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 for setting up the cobra.Command and the args []string, to be directly passed to our functions, so that we can invoke them directly, without relying on cobra to do that.

"github.com/spf13/pflag"
)

func TestPrepareCommandArguments(t *testing.T) {
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 hope I have covered all major cases/formats here.

ExtractContents func(filePath string) []byte
}

func findNonLegacy(rootDir string, name string) []string {
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 unexported these, so that we don't use them directly by mistake, and are reminded to use the handler.

}

// GitHubTemplateHandler handles all the template related functionalities
var GitHubTemplateHandler = TemplateHandler{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The handler with the proper working; to be used when not testing.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thanks for your patience! This changeset is large, so I hope you understand that we might take some time before we dive deeper into this approach and see if it works for us or if we'd want to suggest some changes. 🙇

@AliabbasMerchant
Copy link
Contributor Author

Sure, no problem 😅 👍
Thanks a lot for the update.
(I have kept the code logical per commit, so it should be easy and faster reviewing on a commit-by-commit basis)

@AliabbasMerchant
Copy link
Contributor Author

Any updates? Its been quite a few weeks 😅

@vilmibm vilmibm self-requested a review August 19, 2020 16:17
@vilmibm
Copy link
Contributor

vilmibm commented Aug 19, 2020

@AliabbasMerchant similar apologies as for your other PR: this work got caught by the vortex of our codebase refactor. Are you up for getting this work reconciled with trunk? I think that this testing might actually have become easier as you can now put a template finding helper (for both issue and pr create) into the factory that is passed to commands and inject it in tests.

@AliabbasMerchant
Copy link
Contributor Author

AliabbasMerchant commented Aug 20, 2020

Okay. Cool. No issues.

I kindof lost track amidst the refactoring wave, but hope to resume contributions, seeing that the refactoring part is done, and we are now again open to accept community contributions. 👌

Will do this in 2-3 days and will re-request a review then.

@vilmibm
Copy link
Contributor

vilmibm commented Aug 20, 2020

thanks for your patience and understanding, @AliabbasMerchant !

that refactor was sorely needed and there was no elegant way to balance it against incoming PRs. But yes, it's done now; there is still plenty of cleanup we could do but in terms of fundamental changes we don't have anything planned.

@mislav
Copy link
Contributor

mislav commented Aug 26, 2020

@AliabbasMerchant Thank you! Would you be up to consider a potentially simpler avenue of approaching this? The new command structure might make it easier to stub out the current directory in tests, which we could use to point a command to a fixed location on disk where the fixtures for templates reside. That way you wouldn't have to introduce a whole mechanism for mocking template results, and we could keep the diff at minimum. Let me know if you'd like me to sketch out what I had in mind! 🙇

@AliabbasMerchant
Copy link
Contributor Author

AliabbasMerchant commented Aug 27, 2020

@mislav Sure. I am planning to do this today. (Sorry for the delay)
Will first go through the changes in the command structure, and will definitely keep your suggestions in mind. 👍

@AliabbasMerchant
Copy link
Contributor Author

I went through the refactored code - Great job! The code looks much cleaner and is more manageable ❤️

As @mislav suggested, there is no longer a need for this mocking mechanism, and so this PR is kinda unneeded. Hence, am closing this and have opened #1582 instead.

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.

make template selection test-able

3 participants