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

Make ghrepo a public package #1327

Closed
jlewi opened this issue Jul 5, 2020 · 1 comment
Closed

Make ghrepo a public package #1327

jlewi opened this issue Jul 5, 2020 · 1 comment
Labels
enhancement a request to improve CLI

Comments

@jlewi
Copy link

jlewi commented Jul 5, 2020

Describe the feature or problem you’d like to solve

I would like ghrepo to be a public package
https://github.com/cli/cli/tree/trunk/internal/ghrepo

This way I could reuse it when using the CLI programmatically in go. Right now since its located inside the internal directory its not usable outside it
https://golang.org/doc/go1.4#internalpackages

Here's an example. I want to programmatically create PRs. So my code looks like the following

	baseRepository, err := api.GitHubRepo(client, baseRepo)

	if err != nil {
		return errors.WithStack(errors.Wrapf(err, "There was an error getting repository information."))
	}
	pr, err := api.CreatePullRequest(client, baseRepository, params)
	if err != nil {
		return errors.WithStack(errors.Wrapf(err, "Failed to create pull request"))
	}

So I want to call api.GitHubRepo which requires an argument of type ghrepo.Interface. I don't really want to define my own implementation jut by copying the code in ghrepo. I would rather just reuse it.

@jlewi jlewi added the enhancement a request to improve CLI label Jul 5, 2020
@mislav
Copy link
Contributor

mislav commented Jul 6, 2020

Hi, thanks for explaining how you would use our Go packages.

Personally, I would not recommend importing any packages from our repository into your project other than those under github.com/cli/cli/pkg/*. Currently, our largest packages are command and api, but neither are really suitable for using as a library, since they were not intended to be used that way.

Furthermore, we intentionally put some newer packages under internal/ because they might keep changing and we want to discourage people from importing them.

For your use case I would strongly suggest that, instead of using github.com/cli/cli/api to create pull requests, you should use the github.com/shurcooL/githubv4 library directly for all your GitHub API needs. This will provide greater level of control and long-term stability for your Go project.

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

No branches or pull requests

2 participants