Class: Jets::Git::Azure

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/git/azure.rb

Instance Method Summary collapse

Instance Method Details

#build_typeObject



60
61
62
# File 'lib/jets/git/azure.rb', line 60

def build_type
  ENV['SYSTEM_PULLREQUEST_PULLREQUESTID'] ? 'pull_request' : 'push'
end

#full_repoObject



48
49
50
51
52
53
# File 'lib/jets/git/azure.rb', line 48

def full_repo
  uri = URI(ENV['BUILD_REPOSITORY_URI'])
  org = uri.path.split('/')[1] # since there's a leading /
  repo = ENV['BUILD_REPOSITORY_NAME'] # tongueroo
  "#{org}/#{repo}"
end

#git_branchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jets/git/azure.rb', line 16

def git_branch
  if pr_number
    message = ENV['BUILD_SOURCEVERSIONMESSAGE']
    md = message.match(/Merge pull request \d+ from (.*) into (.*)/)
    if md
      # IE: BUILD_SOURCEVERSIONMESSAGE=Merge pull request 2 from feature into main
      # Its a bit weird but with azure repos with check policy trigger
      md[1]
    else # GitHub and Bitbucket PR has actual branch though
      # IE: SYSTEM_PULLREQUEST_SOURCEBRANCH=feature
      message
    end
  else # push
    ENV['BUILD_SOURCEBRANCHNAME']
  end
end

#git_shaObject



33
34
35
# File 'lib/jets/git/azure.rb', line 33

def git_sha
  ENV['BUILD_SOURCEVERSION']
end

#git_urlObject



37
38
39
# File 'lib/jets/git/azure.rb', line 37

def git_url
  "#{host}/#{full_repo}"
end

#hostObject



42
43
44
45
# File 'lib/jets/git/azure.rb', line 42

def host
  uri = URI(ENV['BUILD_REPOSITORY_URI'])
  "#{uri.scheme}://#{uri.host}"
end

#paramsObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/jets/git/azure.rb', line 3

def params
  params = {
    git_system: 'azure',
    git_branch: git_branch,
    git_sha: git_sha,
    git_dirty: false,
    # git_message: nil,
    # git_version: nil,
  }
  params[:git_url] = git_url if git_url
  params
end

#pr_numberObject

IE: SYSTEM_PULLREQUEST_PULLREQUESTID=2



56
57
58
# File 'lib/jets/git/azure.rb', line 56

def pr_number
  ENV['SYSTEM_PULLREQUEST_PULLREQUESTID']
end