How to enforce commit message for github PR commits only? - github

I know there are multiple node packages out there to enforce commit message format but they all seem to be done pre-commit, locally for 'all' checkins. Is there a way to enforce a commit message format only for the merging of PR to master, and not all checkins?

If you're looking for a native github method to achieve this, then no. There's no way to make github itself check your commit message for some pattern.
Otherwise, what you want is a status check to fail if commits messages do not meet your standard with github configured to disallow PR merge while any check fails. The simples way I can think of is to enable Travis-ci integration for the project and use one of the npm modules you mentioned as the test code and you're done.

There's now a github app that allows this: https://github.com/zeke/semantic-pull-requests. If you want to ensure that all your PR titles are semantically correct (perhaps because you're squash merging) be sure to add the configuration file and specify titleOnly: true

Related

Prevent users from editing master branch in ADF

I'm trying to prevent developers from directly editing and committing to the master branch in ADF.
There is a risk that users can accidently make changes in ADF by not creating a feature branch but instead working directly on master (I've done it myself!)
Is there a way to enforce this in ADF? I do have a branch policy on master that only allows merging via a pull request but don't think this stops developers from working directly on master:
Another way to achieve this is to require a reviewer.
Select "Branch policies":
Turn on the option "Require a minimum number of reviewers":
Set the number of reviewers to 1.
This example shows "Allow requestors to approve their own changes". This setting is optional. If you set it, the user is still prevented from committing to main/master, but can complete their own PRs.
You can deny the contribute permission for the user group in git repo. Check the following official documentation:
https://learn.microsoft.com/en-us/azure/devops/repos/git/branch-permissions?view=azure-devops

How to change URLs in all comments to pull requests in our GitHub project

Our Jenkins server has moved to a different data center, and its DNS name has changed.
All links to previous builds and logs files, recorded in pull requests comments in our GitHub projects, have suddenly become stale.
Is there a way to automatically edit all PR comments, and replace the old DNS name by the new one in the links, to make these links valid again?
For existing PR comment, the (assuming here) GitHub CLI does not seem to expose the feature of editing existing comment.
gh pr comment would only create new PR comments.
You might need to use the GitHub API Update a review comment for a pull request
patch /repos/{owner}/{repo}/pulls/comments/{comment_id}
Which supposed in your case to list comments first.
For existing commit messages which would include Jenkins URLs, you would need to:
clone locally repository
rewrite the commit messages
force push everything (git push --mirror)
Make sure your collaborators re-clone the new history.
To change to commit messages, use newren/git-filter-repo (python-based, to be installed first)
Updating commit/tag messages
If you want to modify commit or tag messages, you can do so with the same syntax as --replace-text, explained above.
For example, with a file named expressions.txt containing
foo==>bar
then running
git filter-repo --replace-message expressions.txt
will replace foo in commit or tag messages with bar.

github API code repository state after each commit

Is there any way to have the full source code repo after each commit?
I mean for example using
https://api.github.com/repos/highcharts/highcharts/commits
would give me a list of commits, but I want to realize what was the effect of that commit to whole repo (I want to check whether any code duplication is added to whole project or not using some automatic tools). Is that possible?
I want to see the code effect, so having repo even after merging each commit would be fine.
Simply implement a listener to a webhook (see "Creating a Webhook"). Set it up to ball your listener at each push event.
You can then do a pull when called by the webhook, and get a fresh updated copy of the repo locally.
For other repos you don't have any control or whose owner is in your team, that webhook approach is not possible.
You would need to implement a scheduled polling approach, through a regular cron job for instance.
That would possible multiple commits, so you need to wrap that pull with a git log as in here.
git checkout master
git fetch
refs=$(git log --format='%H' ..origin/master)
for ref in ${refs}; do
# do your analysis commit by commit
done
git merge origin/master

How can I use pull request name instead of number in TeamCity branch list?

I define branch specification as "+:refs/pull/*/head" and I want to see pull subject instead of pull name.
And is it possible to make link to the github PR from main project page in the TeamCity?
You can connect TeamCity to GitHub through the built-in connector, but I'm not sure that will give you want you want.

concourse ci does not trigger on certain committed files

First, I do know that if I use [ci skip] in the commit message to GitHub it should not trigger based upon the commit message. However, I am only committing one file to GitHub. So instead of using this commit message, is there a way to exclude certain files? I have been researching on https://concourse-ci.org/ for this but have yet to find what I am looking for.
See ignore_paths in the Git resource docs:
https://github.com/concourse/git-resource#source-configuration