33import json
44import datetime
55import subprocess
6- from sumologic import SumoLogic
76from azure .identity import DefaultAzureCredential
87from azure .mgmt .resource .resources .models import Deployment , DeploymentMode
98
@@ -60,23 +59,23 @@ def deploy_template(self):
6059
6160 def get_git_info (self ):
6261 repo_slug = "SumoLogic/sumologic-azure-function"
63- if os .environ .get ("TRAVIS_EVENT_TYPE" ) == "pull_request" :
64- branch_name = os .environ ["TRAVIS_PULL_REQUEST_BRANCH" ]
65- repo_slug = os .environ ["TRAVIS_PULL_REQUEST_SLUG" ]
66- elif os .environ .get ("TRAVIS_EVENT_TYPE" ) == "push" :
67- branch_name = os .environ ["TRAVIS_BRANCH" ]
68- repo_slug = os .environ ["TRAVIS_REPO_SLUG" ]
69- else :
70- git_cmd = "git rev-parse --abbrev-ref HEAD" # will not work in detached state
71- branch_name = subprocess .Popen (git_cmd , shell = True , stdout = subprocess .PIPE ).stdout .read ().strip ()
62+ try :
63+ branch_name = subprocess .check_output ("git branch --show-current" , stderr = subprocess .STDOUT , shell = True )
64+ if not branch_name :
65+ # in detached head state
66+ branch_name = os .environ ["SOURCE_BRANCH" ]
67+ else :
68+ branch_name = self .branch_name .decode ("utf-8" ).strip ()
69+
70+ except Exception as e :
71+ raise Exception (f"Error getting branch name: { e } " )
7272
73- repo_name = "https://github.com/%s" % (repo_slug )
74- if not branch_name or branch_name == "undefined" or not repo_name :
75- raise Exception ("No branch Found" )
76- print ("Testing for repo %s in branch %s" % (repo_name , branch_name ))
73+ if not branch_name or branch_name == "undefined" or not repo_slug :
74+ raise Exception ("No branch found" )
7775
78- if isinstance (branch_name , bytes ):
79- branch_name = branch_name .decode ()
76+ repo_name = f"https://github.com/{ repo_slug } "
77+
78+ print (f"Testing for repo { repo_name } in branch { branch_name } " )
8079
8180 return repo_name , branch_name
8281
@@ -91,7 +90,6 @@ def api_endpoint(self, sumo_deployment):
9190 def create_collector (self , collector_name ):
9291 print ("create_collector start" )
9392 collector_id = None
94- self .sumologic_cli = SumoLogic (os .environ ["SUMO_ACCESS_ID" ], os .environ ["SUMO_ACCESS_KEY" ], self .api_endpoint (os .environ ["SUMO_DEPLOYMENT" ]))
9593 collector = {
9694 'collector' : {
9795 'collectorType' : 'Hosted' ,
0 commit comments