0

So I'm looking for a solution to such a case:

a file with a specific name pattern (say AB_123.sql) is commited to the repository. If the filename differs from the mentioned pattern I'd need a thread to be created. I can cope with the regexp but I'd need a direction as for where to start.

Initially I figured I could probably achieve what I need with a custom hook. So I'd need to write a script that:

  1. lists all the files of the last commit,
  2. checks if there is a file with a certain name pattern,
  3. if so, creates a thread under this commit in gitlab.

For now I have come up with something like this:

LAST_COMMIT=$(git rev-parse --verify HEAD) 
COMMITED_FILES=$(git diff-tree --no-commit-id --name-only -r $LAST_COMMIT)
echo $COMMITED_FILES
if [[ "$COMMITED_FILES" == *"blabla1"* ]]; then
  echo "[INFO]: File(s) found. Creating thread..."
  else
  echo "[INFO]: No files with the specified name pattern found"
fi

What's left here is actually make the script create a thread under this commit when there is a file with specified name patter found.

Yet I cannot find anything on the topic of threads creation with a git command. Is there any?

  • Something like [Danger](https://danger.systems/reference.html) could be useful here. If you are on gitlab premium, you could also use [push rules](https://docs.gitlab.com/ee/push_rules/push_rules.html#prohibited-file-names) – Rekovni Mar 29 '21 at 16:38
  • `of threads creation with a git command` What is a "thread" you are referring to? To issues? Issues are not part of _git_, they are part of _gitlab_. – KamilCuk Mar 31 '21 at 09:31
  • @KamilCuk I'm reffering to a thread you can create under every commit in Gitlab. You have an option to create a comment or start a thread. – Johnny_the_Pickle Mar 31 '21 at 10:09

1 Answers1

1

however I cannot find anything on the topic of threads creation with a git command. Is there any?

Gitlab has great api. Documentation on creating new comments and new issues can be found here: https://docs.gitlab.com/ee/api/discussions.html#create-new-issue-thread https://docs.gitlab.com/ee/api/issues.html#new-issue

Generate an API key for your account, add that key to hidden variable in your project and call gitlab api from gitlab-ci.yml with curl.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111