Can I automatically create a label on a github repo? - github

Our organisation stores code on github and there are certain ways-of-working that we want new repos created by our team to adhere to (e.g. there is a default set of workflows at .github/workflows that each repo should have, a basic .gitignore, linter config files in .github, etc..). Hence we have built repo templates that people can instantiate using a tool called cookiecutter. Its working really well. Note though that cookiecutter only automates the creation of content, it doesn't actually create the git repo (i.e. it doesn't run git init) and it doesn't create anything on github. Hence, the workflow for someone to use one of our templates is:
cookiecutter --output-dir new-repo-name https://github.com/our-org/our-template-repo
cd new-repo-name
git init
gh repo create new-repo-name --private --source=. --remote=upstream
git add .
git push
Hopefully you get the idea.
We then had an idea that we would like to be able to track all the github repos that get created from our templates. We thought a nice way of doing that would be to ensure that each of those repos had a certain label on them.
Hence I'd like to be able to automatically create labels on such newly created repos. Does anyone know a way of doing that? (I was hoping there was perhaps a way of achieving it by putting a certain file into the .github directory, but alas it seems there is no such thing.)

The only labels that come to my mind are the classic GitHub Labels for issues and pull requests. You can also create them with the GitHub CLI. In your case you could add something like gh label create template --description "Created with template xyz" --color 348AA7 to your script. Let me know if this was helpful.

Related

Copy all repos of an organisation to another account

I'm part of an organisation on github and would like to copy all the repos of that organisation to another regular github account at once.
I thought there would be a tool to help me to do this easily but haven't found one yet. What would be the easiest way to approach this? Thank you
I have tried looking into gh but I'm not sure it's the right tool for it. All I'm trying to do is basically cloning all the repos of the organisation I am a part of to another github account in one go
I have tried looking into gh but I'm not sure it's the right tool for it.
Considering there does not seem to be a native feature allowing for a bulk copy you want, gh is actually a good option.
Depending on the fork policy of your organization and the nature of said repositories (public or private), you should be able to write a script, using the GitHub CLI gh, which would:
list the repositories of an organization (gh repo list)
fork it (gh repo fork)
Note that will not copy issues or pull-requests.

How to create a new file in github and add there existing files?

I have files in repository. I want them to be grouped inside a folder. How can I do this?
It seems that I need to add new file if I want to create a folder.
From how you worded your question, it seems like you're trying to work on github directly from the website.
The usual way github works is:
if you have a repo on github and you want to modify it, first 'clone' the repo into your local computer,
use these instructions https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository
then just change folder structure like you would normally on File Explorer (windows) or Finder (mac),
then follow the commit instructions and 'push' up your changes to github
use these instructions
check status of your recent changes:
git status
add the files that you want to include in the commit
git add nameOfFile
check status and the file you want to include should now be green
git status
use this to send to github
git push
Overall github docs here:
https://learn.microsoft.com/en-us/training/modules/introduction-to-github/

Adding GitHub Team and Repo Admins to Repos Created From Template

I have a couple questions related to GitHub template repositories. My team regularly creates repositories from a GitHub template repository. We also have a GitHub team and like to add all of our repositories to our team.
My questions are:
Anytime a new repository is created from our template repository, how can it be automatically added to our GitHub team's list of repositories?
Anytime a new repository is created from our template repository, how can myself (and someone else) automatically be made admins of this new repository (even if we didn't create the repository)?
I've searched all over documentation and Stack Overflow for possible solutions but came up empty handed. I've looked into using CODEOWNER files which might be useful, but don't look like they're designed for this use case. I've also looked into creating new repositories from the GitHub CLI using the template repository and maybe a shell script to add it to our GitHub team, but was hoping for a simpler solution.
Thanks for any thoughts or suggestions!

How to view github pages at specific commit?

I'm trying to view the documentation of a repository at a specific point in time. Is the github pages url hackable enough that I can specific a specific commit hash?
I can't seem to find any information on the web about this.
Once you push your gh-pages branch, old files are replaced by new ones on the static files server. Only one Jekyll build snapshot allowed.
No, you can't. GitHub pages only serves the current content of the gh-pages branch.
You can, however, clone the repo and check out the commit you are looking for locally. You might have to run Jekyll locallly, though, since ts possible to not have the actual HTML files in the gh-pages branch, but a corrrectly set up jekyll page which will get converted by GitHub on-the-fly.
It's not possible via the url but you can always clone the repo and generate the doc yourself at the commit you want.
I am also unable to find an ideal solution. What I do at the moment is to have subdirectories under the branch gh-pages named for example, v1,v2 etc. Then they are accessible as
org.github.io/repo/v1/
org.github.io/repo/v2/
...
This works, but there is almost 100% duplication of content with every version upgrade.

GitHub, composer, autoupdate of standalone repositories

I have a main repository which is core router for mine system modules.
So every module is a standalone repository also.
How can I make that pushing to main repository will fire event to push the updated code to standalone repository?
Just as like https://github.com/Sylius/Sylius - they have main repository (this link) in which they collect pull-requests and standalone repositories like https://github.com/Sylius/SyliusTaxonomyBundle which exists in src/Sylius/Bundle/TaxonomyBundle
Don't they manually push the updates to standalone repos? Or some kind of github hooks? git subtree?
And why they do have the "replace" section in composer.json? How does this works? I didn't get an idea from official documentation :((
Sylius (and Symfony) create separate repositories for their components and bundle so that they can be used independently with composer. They only work in a single repository and use subtree to split the components and bundle into read only repositories.
I don't believe they are technically read-only, this is just an easier workflow than having to pull changes from the subrepo's in every time.
They probably use something like Git Subsplit GitHub WebHook to automatically update the subrepo's.
Using they replace key means that Sylius/Sylius contains Sylius/SyliusCartBundle in its self.
So when using a project which uses Sylius/Sylius and Sylius/SyliusCartBundle, Composer knows not to download Sylius/SyliusCartBundle because it is already provided by Sylius/Sylius.