import os, sys, re, logging
import requests
from github import Github

logging.basicConfig(level=logging.DEBUG)

CIRCLECI_BASEURL = "https://circleci.com/api/v2"
CIRCLECI_ACCESS_TOKEN = os.environ["TAO_CIRCLECI_TOKEN"]
GITHUB_ACCESS_TOKEN = os.environ["TAO_GITHUB_TOKEN"]
g = Github(GITHUB_ACCESS_TOKEN)

if len(sys.argv) < 2:
    raise AttributeError("The image name is required as the first argument.")

image_name = sys.argv[1]
image_name = re.sub(r"[^a-zA-Z0-9-]", " ", image_name)

query = "org:avatao-content language:Dockerfile FROM " + image_name

logging.debug("Searching GitHub with query: '%s'", query)
code_search = g.search_code(query)

circleci_project_slugs = set()
for result in code_search:
    circleci_project_slugs.add(f"gh/{result.repository.organization.login}/{result.repository.name}")
logging.debug("Found %d candidate repositories.", len(circleci_project_slugs))

current_item = 1
for slug in circleci_project_slugs:
    logging.debug("[%d/%d] Triggering CI pipeline for: %s", current_item, len(circleci_project_slugs), slug)
    requests.post(f"{CIRCLECI_BASEURL}/project/{slug}/pipeline", headers={"Circle-Token": CIRCLECI_ACCESS_TOKEN})
    current_item += 1

import os, sys, re
import requests
from github import Github

CIRCLECI_BASEURL = "https://circleci.com/api/v2"
CIRCLECI_ACCESS_TOKEN = os.environ["AVATAO_CIRCLECI_TOKEN"]
GITHUB_ACCESS_TOKEN = os.environ["AVATAO_GITHUB_TOKEN"]
g = Github(GITHUB_ACCESS_TOKEN)

if len(sys.argv) < 2:
    raise AttributeError("The image name is required as the first argument.")

image_name = sys.argv[1]
image_name = re.sub(r"[^a-zA-Z0-9-]", " ", image_name)

query = "org:avatao-content language:Dockerfile " + image_name

print("Searching GitHub with query: '%s'" % query)
code_search = g.search_code(query)

circleci_project_slugs = set()
for result in code_search:
    circleci_project_slugs.add(f"gh/{result.repository.organization.login}/{result.repository.name}")
print("Found %d candidate repositories." % len(circleci_project_slugs))

current_item = 1
for slug in circleci_project_slugs:
    print("[%d/%d] Triggering CI pipeline for: %s" % (current_item, len(circleci_project_slugs), slug))
    requests.post(f"{CIRCLECI_BASEURL}/project/{slug}/pipeline", headers={"Circle-Token": CIRCLECI_ACCESS_TOKEN})
    current_item += 1

Rename env vars & modify query
Rename env vars & modify query

- import os, sys, re, logging
+ import os, sys, re
  import requests
  from github import Github
  
- logging.basicConfig(level=logging.DEBUG)
- 
  CIRCLECI_BASEURL = "https://circleci.com/api/v2"
- CIRCLECI_ACCESS_TOKEN = os.environ["TAO_CIRCLECI_TOKEN"]
+ CIRCLECI_ACCESS_TOKEN = os.environ["AVATAO_CIRCLECI_TOKEN"]
- GITHUB_ACCESS_TOKEN = os.environ["TAO_GITHUB_TOKEN"]
+ GITHUB_ACCESS_TOKEN = os.environ["AVATAO_GITHUB_TOKEN"]
  g = Github(GITHUB_ACCESS_TOKEN)
  
  if len(sys.argv) < 2:
      raise AttributeError("The image name is required as the first argument.")
  
  image_name = sys.argv[1]
  image_name = re.sub(r"[^a-zA-Z0-9-]", " ", image_name)
  
- query = "org:avatao-content language:Dockerfile FROM " + image_name
+ query = "org:avatao-content language:Dockerfile " + image_name
  
- logging.debug("Searching GitHub with query: '%s'", query)
+ print("Searching GitHub with query: '%s'" % query)
  code_search = g.search_code(query)
  
  circleci_project_slugs = set()
  for result in code_search:
      circleci_project_slugs.add(f"gh/{result.repository.organization.login}/{result.repository.name}")
- logging.debug("Found %d candidate repositories.", len(circleci_project_slugs))
+ print("Found %d candidate repositories." % len(circleci_project_slugs))
  
  current_item = 1
  for slug in circleci_project_slugs:
-     logging.debug("[%d/%d] Triggering CI pipeline for: %s", current_item, len(circleci_project_slugs), slug)
+     print("[%d/%d] Triggering CI pipeline for: %s" % (current_item, len(circleci_project_slugs), slug))
      requests.post(f"{CIRCLECI_BASEURL}/project/{slug}/pipeline", headers={"Circle-Token": CIRCLECI_ACCESS_TOKEN})
      current_item += 1
  
Rename env vars & modify query
## Code Before:
import os, sys, re, logging
import requests
from github import Github

logging.basicConfig(level=logging.DEBUG)

CIRCLECI_BASEURL = "https://circleci.com/api/v2"
CIRCLECI_ACCESS_TOKEN = os.environ["TAO_CIRCLECI_TOKEN"]
GITHUB_ACCESS_TOKEN = os.environ["TAO_GITHUB_TOKEN"]
g = Github(GITHUB_ACCESS_TOKEN)

if len(sys.argv) < 2:
    raise AttributeError("The image name is required as the first argument.")

image_name = sys.argv[1]
image_name = re.sub(r"[^a-zA-Z0-9-]", " ", image_name)

query = "org:avatao-content language:Dockerfile FROM " + image_name

logging.debug("Searching GitHub with query: '%s'", query)
code_search = g.search_code(query)

circleci_project_slugs = set()
for result in code_search:
    circleci_project_slugs.add(f"gh/{result.repository.organization.login}/{result.repository.name}")
logging.debug("Found %d candidate repositories.", len(circleci_project_slugs))

current_item = 1
for slug in circleci_project_slugs:
    logging.debug("[%d/%d] Triggering CI pipeline for: %s", current_item, len(circleci_project_slugs), slug)
    requests.post(f"{CIRCLECI_BASEURL}/project/{slug}/pipeline", headers={"Circle-Token": CIRCLECI_ACCESS_TOKEN})
    current_item += 1

## Instruction:
Rename env vars & modify query
## Code After:
import os, sys, re
import requests
from github import Github

CIRCLECI_BASEURL = "https://circleci.com/api/v2"
CIRCLECI_ACCESS_TOKEN = os.environ["AVATAO_CIRCLECI_TOKEN"]
GITHUB_ACCESS_TOKEN = os.environ["AVATAO_GITHUB_TOKEN"]
g = Github(GITHUB_ACCESS_TOKEN)

if len(sys.argv) < 2:
    raise AttributeError("The image name is required as the first argument.")

image_name = sys.argv[1]
image_name = re.sub(r"[^a-zA-Z0-9-]", " ", image_name)

query = "org:avatao-content language:Dockerfile " + image_name

print("Searching GitHub with query: '%s'" % query)
code_search = g.search_code(query)

circleci_project_slugs = set()
for result in code_search:
    circleci_project_slugs.add(f"gh/{result.repository.organization.login}/{result.repository.name}")
print("Found %d candidate repositories." % len(circleci_project_slugs))

current_item = 1
for slug in circleci_project_slugs:
    print("[%d/%d] Triggering CI pipeline for: %s" % (current_item, len(circleci_project_slugs), slug))
    requests.post(f"{CIRCLECI_BASEURL}/project/{slug}/pipeline", headers={"Circle-Token": CIRCLECI_ACCESS_TOKEN})
    current_item += 1
