Project

stash-api

0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Stash API is a ruby library to interact with stash rest API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.10
~> 1.1
 Project Readme

Stash-API

Ruby Stash API library.

Gem Version

Build Status

Usage

#!/usr/bin/ruby

require 'json'
require 'stash-api'

stash_client = Stash::Client.new('username', 'password')

#Setup hook configurations for the repository
hooks = {
  'com.zerosumtech.wparad.stash.stash-http-request-trigger:postReceiveHook' => {
	:config => {
	  "url"=>"https://jenkins/job/JenkinsJobName.Merge/buildWithParameters?cause=Stash&token=TOKEN",
	  "refRegex"=>"^refs/heads/release/.*$",
	  "prurl"=>"https://jenkins/job/JenkinsJobName.PR/buildWithParameters?cause=Stash&token=TOKEN",
	}
  },
  'com.atlassian.stash.plugin.stash-protect-unmerged-branch-hook:protect-unmerged-branch-hook' => {}
  }
}

stash_client.set_hooks(hooks)
puts JSON::pretty_generate(stash_client.get_hooks())

#Set branching permissions
permissions = [
  {
	'type' => 'fast-forward-only',
	'matcher' => {
	  'id' => 'development',
	  'type' => {
		'id' => 'MODEL_BRANCH'
	  }
	}
  },
  {
	'type' => 'no-deletes',
	'matcher' => {
	  'id' => 'development',
	  'type' => {
		'id' => 'MODEL_BRANCH'
	  }
	}
  }
]
stash_client.set_branch_permissions(permissions)
puts JSON::pretty_generate(stash_client.get_branch_permissions())

#Set up automatic merging
stash_client.set_automatic_merging()
puts stash_client.get_automatic_merging()

#Set up pull request merge settings
puts stash_client.get_pull_request_settings()
stash_client.set_pull_request_settings({:builds => 1, :approvers => 1})

stash_explorer = Stash::Explorer.new('username', 'password', 'stash.server.com')
stash_explorer.get_repositories('MyKey').each do |repo|
  content = stash.get_file('MyKey', repo, 'Gemfile.lock')
  puts "#{repo}: #{content}"
end