Skip to content

Commit 36084d1

Browse files
committed
Git repo and branch with PR comments
1 parent 5c61ffd commit 36084d1

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

EventHubs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ azure-mgmt-resource==23.0.1
66
azure-mgmt-eventhub==11.0.0
77
azure-eventhub==5.11.5
88
azure-mgmt-storage==21.1.0
9-
zure-mgmt-loganalytics==12.0.0
9+
azure-mgmt-loganalytics==12.0.0
1010
sumologic-sdk==0.1.15

EventHubs/tests/baseeventhubtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import json
44
from datetime import timedelta
5+
from sumologic import SumoLogic
56
from azure.mgmt.resource import ResourceManagementClient
67
from azure.mgmt.eventhub import EventHubManagementClient
78
from azure.eventhub import EventHubProducerClient
@@ -20,6 +21,7 @@ def setUp(self):
2021
self.resource_client = ResourceManagementClient(self.azure_credential,
2122
self.subscription_id)
2223
self.repo_name, self.branch_name = self.get_git_info()
24+
self.sumologic_cli = SumoLogic(os.environ["SUMO_ACCESS_ID"], os.environ["SUMO_ACCESS_KEY"], self.api_endpoint(os.environ["SUMO_DEPLOYMENT"]))
2325
self.collector_id = self.create_collector(self.collector_name)
2426
self.sumo_source_id, self.sumo_endpoint_url = self.create_source(self.collector_id, self.source_name)
2527

@@ -28,6 +30,7 @@ def tearDown(self):
2830
self.delete_resource_group()
2931
self.delete_source(self.collector_id, self.sumo_source_id)
3032
self.delete_collector(self.collector_id)
33+
self.sumologic_cli.session.close()
3134

3235
def get_resource_name(self, resprefix, restype):
3336
for item in self.resource_client.resources.list_by_resource_group(self.RESOURCE_GROUP_NAME):

test_utils/basetest.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import datetime
55
import subprocess
6-
from sumologic import SumoLogic
76
from azure.identity import DefaultAzureCredential
87
from 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

Comments
 (0)