美文网首页git使用锦集
git自定义阈值限制仓库大小超过阈值拦截

git自定义阈值限制仓库大小超过阈值拦截

作者: 大鹏一怒乘风起 | 来源:发表于2020-10-15 11:56 被阅读0次

    1.定义api接口地址,直接返回 0  1  2 ,0 不限制项目,1 ,限制项目,2,没有该项目大小

    2.若请求返回为2,则向该接口发送post请求,把项目大小提交至该接口,在请求api接口地址,看是否限制

    #!/bin/bash

    BaseUrl='https://xxxx'

    pathdir=$(echo $GIT_OBJECT_DIRECTORY|awk -F'\.git' '{print $1}')

    #echo $pathdir

    pathdirsize=$(du -sb $pathdir.git|awk '{print $1}')

    #echo "pathdir:$pathdir.git pathsize:$pathdirsize"

    aa=$(echo $GL_REPOSITORY|awk -F'-' '{print $2}')

    repositoryStatus=$(curl -s "$BaseUrl"/api/"$aa")

    #echo $repositoryStatus;

    #echo $aa

    if [ "$repositoryStatus" == "1" ];then

    echo "id:$aa project too large!The project size exceeds the limit!!!"

    exit 1;

    elif [ "$repositoryStatus" == "2" ];then

      curl -X POST "$BaseUrl/api/$aa" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{\"GitProjectId\":$aa,\"RepositorySize\":$pathdirsize}"

      echo "111$BaseUrl 222$aa 333$pathdirsize ------"

      repository1Status=$(curl -s "$BaseUrl"/api/"$aa")

      if [ "$repository1Status" == "1" ];then

            echo "id:$aa project too large!The project size:$pathdirsize exceeds the limit, please contact the RDC administrator!!!"

            exit 1;

      else

          exit 0;

      fi

    else

      exit 0;

    fi

    相关文章

      网友评论

        本文标题:git自定义阈值限制仓库大小超过阈值拦截

        本文链接:https://www.haomeiwen.com/subject/vqbnpktx.html