Armando Peña
Armando Peña

Reputation: 75

Gitlab changelog API error: commit start range is unspecified

I am writing a script to generate a changelog on Gitlab with the commits to my main branch by using the changelogs API. The project is already quite advanced but I had never done this before. I followed a few guides and ended up creating a pipeline that would launch a script that then uses the Gitlab API to generate a changelog file.

This is my pipeline:

stages:
  - tag

changelog:
  stage: tag
  image: curlimages/curl:7.79.1
  only:
    - main
  script:
    - '. gitlab-changelog.sh ${API_TOKEN} https://gitlab.com/api/v4/projects/${PROJECT_ID}/repository/changelog'

And this is my script:

#!/bin/bash

app_version=$(cat VERSION.md)
branch=main

echo "CHANGELOGS SCRIPT IS RUNNING!"

link=https://gitlab.com/<project-path>/-/blob/${branch}/CHANGELOG.md

GITLAB_PROJECT_ACCESS_TOKEN=$1
GITLAB_PROJECT_CHANGELOG_API=$2

response=$(curl --write-out '%{http_code}' --request POST --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_ACCESS_TOKEN}" --data "version=${app_version}&branch=${branch}" "${GITLAB_PROJECT_CHANGELOG_API}")

echo "response: $response"

if [ $response == 200 ]
then echo "Updated changelog: ${link}"
else echo "An error occurred when requesting GitLab API"
fi;

With this I was expecting that when ever I push a commit to the main branch, with the following format:

Title

Body

Changelog: added

The API would take care of creating or updating the CHANGELOG.md file

But whenever I make a commit I receive this answer from the API :

{"message":"Failed to generate the changelog: The commit start range is unspecified, and no previous tag could be found to use instead"}422

I think the error might be on the configuration of the project or the commit messages but I didn't found more information about this error on the documentation.

UPDATE I already fixed the issue by adding a from to the curl request

response=$(curl --write-out '%{http_code}' --request POST --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_ACCESS_TOKEN}" --data "version=${app_version}&branch=${branch}&from=${START_COMMIT_SHA}" "${GITLAB_PROJECT_CHANGELOG_API}")

but now I am getting the following error

Failed to generate the changelog: denied by custom hooks

Upvotes: 0

Views: 1890

Answers (1)

nyet
nyet

Reputation: 596

See your push rules (or predefined push rules if a group) in Repository->Settings

https://gitlab.com/gitlab-org/gitlab-web-ide/-/issues/122

Your commit violates one or more of them.

Upvotes: 0

Related Questions