Skip to content

Instantly share code, notes, and snippets.

@KenshoFujisaki
Created March 15, 2015 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenshoFujisaki/760a9d62263c488319e3 to your computer and use it in GitHub Desktop.
Save KenshoFujisaki/760a9d62263c488319e3 to your computer and use it in GitHub Desktop.
GitLab向けリモートフックスクリプト:トピックブランチ以外のpush禁止
#!/opt/gitlab/embedded/bin/ruby
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating gitlab-shell!
refname = ARGV[0]
key_id = ENV['GL_ID']
repo_path = Dir.pwd
# トピックブランチ(feature/bugfix/refactoring)以外のpushを禁じる
regex_matches = /(?<topic_type>feature|bugfix|refactoring)(?<topic_type_detail>|_.*)\/(?<ticket_number>\d+)/.match(refname)
if regex_matches.nil?
p "----------------------------------------------------------------------------------"
p "This push is not allowed. The branch name is invalid."
p "Following branch name is only allowed: /(feature|bugfix|refactoring)(|_.*)\/(\d+)/"
p "----------------------------------------------------------------------------------"
exit 1
end
require_relative '../lib/gitlab_update'
GitlabUpdate.new(repo_path, key_id, refname).exec
@KenshoFujisaki
Copy link
Author

/var/opt/gitlab/git-data/repositories/[user_name]/[repository_name].git/hooks/update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment