How to create a post-service hook on a public github repository? - github

I have no problem in creating hooks for my own repositories, however, I haven't found a way to create such hooks for a public repo.
Is it possible in any way?

Yes, you're correct - it seems that it is not possible to subscribe to events of a repository you do not own (using PSHB), or create hooks for such repos.
Perhaps this would be a nice feature request to send to support#github.com.

Related

Use a single repo with multiple projects

I have a repository called Notifications whose sole job is to send notifications / emails . I want to use that code at several other repositories so that when I update Notifications repo, all other repos use that code directly from github so that there is just a single source of truth. I am not able to understand how to achieve this. Can somebody please help?
Best practice here is to package the code in the Notifications repo into an artifact, and then import that as a dependency in all the projects you need it.
If you have a code that cannot be packaged so straight-forward, you can sync the repos by installing a web-hook on the Notifications repo, which will be triggered whenever a merge in master (or any other event) happens.
The web-hook code will take the hash of the commit, and it will apply that commit to all the repos you need.
Here is a similar post that you can check out.
It takes a bit of scripting work, but I think it's a viable solution.

Share GitHub Actions workflow within organization

It seems like it's possible to create a .github repository within the organization and share workflows across my org.
The problem is, it seems like the .github repo must be public. What's the idea behind this? Why would I want to create a public repo for all my workflows within my organization?
I thought switching to GitHub Enterprise would help me on this matter, but it doesn't looks like it does.
Any ideas?
https://github.com/github/roadmap/issues/51
private repository for workflow templates is on the Roadmap but its indeed does not supported at the moment.
too bad.
There is a workaround to share your github action workflows privately. You can create a private repo and save your workflows as template.
https://medium.com/#er.singh.nitin/how-to-share-the-github-actions-workflow-in-an-organization-privately-c3bb3e0deb3
This is now generally available for GitHub Enterprises
https://github.blog/changelog/2022-03-04-sharing-github-actions-within-your-enterprise-is-now-ga/
https://docs.github.com/enterprise-cloud#latest/actions/creating-actions/sharing-actions-and-workflows-with-your-enterprise

How to check whether I have a fork of a given GitHub repo?

Let's say there is a repository foo/bar which I forked to me/custom-bar. How do I check programmatically (API call maybe?) given foo/bar that there exists a fork that I own from this upstream? Currently, GitHub has the repos/owner/id/forks API endpoint that returns upto 100 entries if you explicitly mention it. I don't see any parameters for creating a custom query for this particular problem. Counting in the rate-limiting and stuff, I don't think it's possible to know this using this API endpoint if I had say a fork of the linux project where over 20k+ forks exist. Is there any fast and efficient way to know this?
Note: I don't want to use authentication if at all possible.
New option (June 2022), directly on GitHub (instead of locally through API)
The repository fork button now displays existing forks
A dropdown has been added to the Fork button to help you quickly find your forks of a repository. This includes forks in your personal account and in organizations that you're a member of.
This feature was inspired by Refined GitHub – an impressive open source project maintained by #fregante.
The feature was requested of GitHub through the GitHub Stars program.
Read more about forking a repository in the GitHub documentation.
We appreciate feedback on this and other topics in GitHub's public feedback discussions.
As a workaround... you can always try to fork your own repo (POST /repos/:owner/:repo/forks).
As explained in "Is it possible to 'fork a fork' in Github?", that won't be generally possible (for a sigle non-organization account) to do if your own repo is itself a fork.
A solution here will be:
Check your repositories using GET /users/:username/repos
For each repo which fork property is true, GEt repository information using GET /repos/:owner/:repo
Check the parent object in json response (that contains parent folder of fork) and validate if full_name is your foo/bar repo

How to prevent pushes to a private repository in Github

We have a repository in GitHub. We want a group of developers to be able to view and fork this repository. But we'd like to prevent them from committing to our branches. Instead, we want this group of developers to fork the repo and create pull requests to contribute. Is there any way to achieve this in GitHub?
Access control is no longer available for private repositories. Both read and write access is given to the collaborators.
If a collaborator will have only read access to a repository, you must create an organization.
You need to add collaborator to your repository and give them just read access, look following article:
https://help.github.com/articles/adding-collaborators-to-a-personal-repository/

How to have a private repository with public issue tracker on GitHub?

I am going to release some beta version of my application to the community. Project is stored on GitHub in the private repository.
I would like to allow this community to report bugs and place them directly on GitHub Issues tab - it's not provided by GitHub right now. Do you have any idea, how to cover this flow ?
Not possible as of 2019-09 as documented at: https://help.github.com/articles/issues-only-access-permissions/ (archive):
GitHub does not provide issues-only access permissions, but you can accomplish this using a second repository which contains only the issues.
They suggest that you create a separate public repository just for the issues instead.
Possible same request: Github-like hosting, with private source, public ticketing system
Bitbucket provides this. You can keep the code private but make tracker public (anyone can view, create, and comment on issues).
Use the API access and program some minimal frontend yourself - https://docs.github.com/en/rest/issues