How to force refresh tags in commit view after post-receive hook?

Jędrzej Andrykowski August 30, 2017

I create a simple bash post-receive hook which adds tag to last commit. Hook is working because:

1. I can fetch created tags to my local repo,

2. I can see created tags on revision selector(branch, tags)

3. I can see tags when I request to the Bitbucket API

Unfortunately I cannot see this tags on commits view. It seems that the commits view is not refreshed. The funny thing is, when I add tag from view (go to commit and manually click "add tag") the not refreshed tags from my hook are appear. So, is there some possibility to force refresh the tags in the commit view after post receive hook executed?

1 answer

0 votes
Jeff Thomas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 7, 2017

Hi,

Can you provide the post-receive hook that you're using so I can try to reproduce the problem locally?

Also, please confirm the version of Bitbucket Server that you're running.

Cheers,

Jeff

Jędrzej Andrykowski September 18, 2017
#!/usr/bin/env bash

CURRENT_COMMIT=$(git rev-parse --short HEAD)
CURRENT_TAG=$(git tag --points-at ${CURRENT_COMMIT})
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

if [ ${BRANCH_NAME} = 'master' ]; then
    if [ -n "$CURRENT_TAG" ]; then
        echo "Current tag is: $CURRENT_TAG"
    else
        LAST_TAG_COMMIT=$(git rev-list --tags --max-count=1)
        LAST_TAGS=$(git tag --points-at ${LAST_TAG_COMMIT})

        IFS=' ' read -r -a array <<< ${LAST_TAGS}

        for i in "${array[@]}"
        do
            if [ -n "$i" -a -z "${i/v[0-9]*.[0-9]*.[0-9]*}" ] ; then
                LAST_TAG=${i}
            fi
        done

        if [ -n "$LAST_TAG" ]; then
            VERSION=`echo ${LAST_TAG} | sed "s/v//"`
            IFS='.' read -r -a array <<< ${VERSION}

            MAJOR="${array[0]}"
            MINOR="${array[1]}"
            PATCH="${array[2]}"

            MESSAGE=$(git log --format=%B -n 1 ${CURRENT_COMMIT} | xargs)
            CHOICE=`echo ${MESSAGE} | sed "s/.*\[\([^]]*\)\].*/\1/g"`

            case "$CHOICE" in
                "C") MAJOR=$(($MAJOR + 1))
                MINOR=0
                PATCH=0
                ;;
                "F") MINOR=$(($MINOR + 1))
                PATCH=0;;
                "B") PATCH=$(($PATCH + 1))
                ;;
                *) PATCH=$(($PATCH + 1))
                ;;
            esac

            NEW_VERSION=${MAJOR}.${MINOR}.${PATCH}
        else
            NEW_VERSION="0.0.1"
        fi

    NEW_TAG=v${NEW_VERSION}

    git tag -fa ${NEW_TAG} -m 'Release version ${NEW_VERSION}' ${CURRENT_COMMIT}
    echo "New tag created: $NEW_TAG at commit ${CURRENT_COMMIT}"

    fi
fi

 

 

Jędrzej Andrykowski September 18, 2017

BitBucket version v5.2.2

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events