cli icon indicating copy to clipboard operation
cli copied to clipboard

Provide inbuilt way to add a license to an existing repository

Open john-h-k opened this issue 2 years ago • 10 comments

Describe the feature or problem you’d like to solve

A clear and concise description of what the feature or problem is.

Proposed solution

Adding a new command add-license (or just license) either at the root level or under repo. You could then select one of the standard GitHub licenses and add to the repo

Additional context

There are extensions such as https://github.com/mislav/gh-license that do this but personally I think it is a common enough use case and a small enough project (I would be happy to do the workload if this feature is wanted) that it is justified to be in the CLI itself

john-h-k avatar Feb 02 '23 13:02 john-h-k

I agree this is a very common use case and core enough to GitHub that someone might not think to seek an extension for it.

Let's go with gh repo add-license; I want to see an interactive selector for a no-argument invocation like the one in gh repo create (refactoring to reuse code as able if possible).

vilmibm avatar Feb 27 '23 17:02 vilmibm

Brilliant - I’m happy to take this, could you assign me?

john-h-k avatar Mar 01 '23 09:03 john-h-k

@john-h-k We generally do not assign community members to an issue but feel free to start work on it 👍

samcoe avatar Mar 01 '23 21:03 samcoe

I'll assign myself so someone is accountable to it getting reviewed and merged and such.

vilmibm avatar Mar 01 '23 21:03 vilmibm

Should it still support an interactive flow with an explicit repo? I feel like doing gh repo add-license my-repo is probably a common enough usage that it could still be useful to have the interactive

john-h-k avatar Mar 06 '23 11:03 john-h-k

Also, should it require the repo to be cloned?

john-h-k avatar Mar 06 '23 11:03 john-h-k

Realizing now how vague I was being, sorry! here's a more complete mock-up:

# not in a local clone
$ gh repo add-license
x error: not in a locally cloned repository

# not in a local clone, but -R used
$ gh repo -Rvilmibm/testing add-license 
x error: not in a locally cloned repository

# not in a local clone, but -R and -w/--web used:
$ gh repo -Rvilmibm/testing add-license -w
Opening https://github.com/vilmibm/testing/community/license/new in your browser...

# in a local clone, no argument
$ gh repo add-license
? Choose a license <GPL-3.0>
✓ Added LICENSE file.

You can now run `git add LICENSE && git commit` to save this change or `rm LICENSE` to undo. 

# in a local clone, argument
$ gh repo add-license GPL-3.0
$ git add LICENSE && git commit -m'add license' && git push

If there is a way to avoid the local clone I'm all ears but aside from --web I couldn't think of one. I'm also open to a --commit flag which does the add and commit, but I don't think that's critical. If you do feel like adding it it should warn if there are untracked changes when the command is invoked.

Let me know if I'm missing anything or if you have more questions.

vilmibm avatar Mar 08 '23 20:03 vilmibm

Sorry for the silence I've had a very busy month, but back on this now. I'm gonna open a (very WIP) PR for this

john-h-k avatar Apr 24 '23 11:04 john-h-k

Is this issue, still being worked on?

vikaspoddar avatar Sep 13 '24 19:09 vikaspoddar

@VikasPoddar it's open to community contribution. If you're interested you could continue from the PR that went stale https://github.com/cli/cli/pull/7358

williammartin avatar Sep 13 '24 21:09 williammartin

@john-h-k : catching up on this issue relative to https://github.com/cli/cli/issues/8946, I want to see if you checked out the gh repo license commandset to browse, view, and use licenses.

This should allow you to create and commit license files locally:

# Create a LICENSE.md with the MIT license
$ gh repo license view MIT > LICENSE.md

andyfeller avatar Mar 28 '25 13:03 andyfeller

@andyfeller I think this issue could be closed unless we want to have a distinct command or command option for creating a license file rather than relying on the shell's output redirection. Personally, I'm not in favour of that. I'd prefer to leave it how it is and require output redirection when the user wants that.

BagToad avatar Apr 02 '25 17:04 BagToad

@john-h-k : catching up on this issue relative to #8946, I want to see if you checked out the gh repo license commandset to browse, view, and use licenses.

This should allow you to create and commit license files locally:

Create a LICENSE.md with the MIT license

$ gh repo license view MIT > LICENSE.md

This seems great, shall close this issue

john-h-k avatar Apr 09 '25 11:04 john-h-k