PyBugReporter 1.0.15__tar.gz → 1.0.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyBugReporter
3
- Version: 1.0.15
3
+ Version: 1.0.18
4
4
  Summary: A python library for catching thrown exceptions and automatically creating issues on a GitHub repo.
5
5
  Home-page: https://github.com/byuawsfhtl/PyBugReporter.git
6
6
  Author: Record Linking Lab
@@ -0,0 +1 @@
1
+ __version__ = '1.0.18'
@@ -7,6 +7,11 @@ from PyBugReporter.src.DiscordBot import DiscordBot
7
7
 
8
8
  from python_graphql_client import GraphqlClient
9
9
 
10
+ BUG_LABEL_NAME: str = "bug"
11
+ AUTO_LABEL_NAME: str = "auto generated"
12
+ BUG_LABEL_COLOR: str = "d73a4a"
13
+ AUTO_LABEL_COLOR: str = "ededed"
14
+
10
15
  class NotCreatedError(Exception):
11
16
  """Raised when someone tries to report a bug to a repo that has not been set up as a reporting destination through setVars.
12
17
  """
@@ -226,8 +231,8 @@ class BugReporter:
226
231
 
227
232
  # query variables
228
233
  repoId = await self._getRepoId_async(self.handlers[repoName])
229
- bugLabel = "LA_kwDOJ3JPj88AAAABU1q15w"
230
- autoLabel = "LA_kwDOJ3JPj88AAAABU1q2DA"
234
+ bugLabel = await self._get_or_create_label_id_async(self.handlers[repoName], repoId, BUG_LABEL_NAME, BUG_LABEL_COLOR)
235
+ autoLabel = await self._get_or_create_label_id_async(self.handlers[repoName], repoId, AUTO_LABEL_NAME, AUTO_LABEL_COLOR)
231
236
 
232
237
  # Create new issue
233
238
  createIssue = """
@@ -344,7 +349,7 @@ class BugReporter:
344
349
  headers = {"Authorization": f"Bearer {handler.githubKey}"}
345
350
 
346
351
  # query variables
347
- autoLabel = "auto generated"
352
+ autoLabel = AUTO_LABEL_NAME
348
353
 
349
354
  # Query to return all issues with auto gen label
350
355
  findIssue = """
@@ -413,6 +418,64 @@ class BugReporter:
413
418
  repoID = await client.execute_async(query=getID, variables=variables, headers=headers)
414
419
  return repoID['data']['repository']['id']
415
420
 
421
+ @classmethod
422
+ async def _get_or_create_label_id_async(cls, handler: BugHandler, repo_id: str, label_name: str, color: str = "ededed") -> str:
423
+ """Gets a label ID from the repository, creating it if it does not exist.
424
+
425
+ Args:
426
+ handler (BugHandler): the object of reporting details
427
+ repo_id (str): the repository ID
428
+ label_name (str): the name of the label
429
+ color (str): the hex color code for creating the label
430
+
431
+ Returns:
432
+ str: the label ID
433
+ """
434
+ client = GraphqlClient(endpoint="https://api.github.com/graphql")
435
+ headers = {"Authorization": f"Bearer {handler.githubKey}"}
436
+
437
+ getLabelQuery = """
438
+ query getLabel($owner: String!, $name: String!, $labelName: String!) {
439
+ repository(owner: $owner, name: $name) {
440
+ label(name: $labelName) {
441
+ id
442
+ }
443
+ }
444
+ }
445
+ """
446
+
447
+ variables = {
448
+ "owner": handler.orgName,
449
+ "name": handler.repoName,
450
+ "labelName": label_name
451
+ }
452
+
453
+ result = await client.execute_async(query=getLabelQuery, variables=variables, headers=headers)
454
+ labelData = result.get("data", {}).get("repository", {}).get("label")
455
+ if labelData and labelData.get("id"):
456
+ return labelData["id"]
457
+
458
+ createLabelMutation = """
459
+ mutation createLabel($input: CreateLabelInput!) {
460
+ createLabel(input: $input) {
461
+ label {
462
+ id
463
+ }
464
+ }
465
+ }
466
+ """
467
+
468
+ createVariables = {
469
+ "input": {
470
+ "repositoryId": repo_id,
471
+ "name": label_name,
472
+ "color": color
473
+ }
474
+ }
475
+
476
+ createResult = await client.execute_async(query=createLabelMutation, variables=createVariables, headers=headers)
477
+ return createResult["data"]["createLabel"]["label"]["id"]
478
+
416
479
  @classmethod
417
480
  def manualBugReport(cls, repoName: str, errorTitle: str, errorMessage: str) -> None:
418
481
  """Manually sends a bug report to the Github repository.
@@ -444,8 +507,8 @@ class BugReporter:
444
507
 
445
508
  # query variables
446
509
  repoId = await cls._getRepoId_async(cls, handler)
447
- bugLabel = "LA_kwDOJ3JPj88AAAABU1q15w"
448
- autoLabel = "LA_kwDOJ3JPj88AAAABU1q2DA"
510
+ bugLabel = await cls._get_or_create_label_id_async(handler, repoId, BUG_LABEL_NAME, BUG_LABEL_COLOR)
511
+ autoLabel = await cls._get_or_create_label_id_async(handler, repoId, AUTO_LABEL_NAME, AUTO_LABEL_COLOR)
449
512
 
450
513
  # Create new issue
451
514
  createIssue = """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyBugReporter
3
- Version: 1.0.15
3
+ Version: 1.0.18
4
4
  Summary: A python library for catching thrown exceptions and automatically creating issues on a GitHub repo.
5
5
  Home-page: https://github.com/byuawsfhtl/PyBugReporter.git
6
6
  Author: Record Linking Lab
@@ -1 +0,0 @@
1
- __version__ = '1.0.15'
File without changes
File without changes
File without changes
File without changes