gitlab commit thread created automatically on a condition

373 Views Asked by At

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?

1

There are 1 best solutions below

0
KamilCuk On

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.