Skip to content

Commit

Permalink
Revert "loop to test issue or PR (#166)" (#167)
Browse files Browse the repository at this point in the history
This reverts commit c451b50.
  • Loading branch information
JesseCaddell authored Jan 14, 2025
1 parent c451b50 commit d9465e7
Showing 1 changed file with 52 additions and 58 deletions.
110 changes: 52 additions & 58 deletions post-issue-smartsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,66 @@

SMART_ACCESS_TOKEN = os.environ['SMART_ACCESS_TOKEN']
GITHUB_ACCESS_TOKEN = os.environ['GH_ACCESS_TOKEN']
ISSUE_NUM = int(os.environ['ISSUE_NUM']) # Ensure ISSUE_NUM is an integer
ISSUE_NUM = os.environ['ISSUE_NUM']

# Initialize client. Uses the API token in the environment variable 'SMARTSHEET_ACCESS_TOKEN'
smart = smartsheet.Smartsheet(SMART_ACCESS_TOKEN)
# Make sure we don't miss any error
smart.errors_as_exceptions(True)

# Log all calls
logging.basicConfig(filename='rwsheet.log', level=logging.INFO)

# Loop to find a valid issue
while True:
# GET request to GitHub API
response = requests.get(
f'https://api.github.com/repos/SeattleColleges/belindas-closet-nestjs/issues/{ISSUE_NUM}',
headers={
'Authorization': f'Bearer {GITHUB_ACCESS_TOKEN}',
'Content-Type': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
}
)

# Check for valid response
if response.status_code != 200:
print(f"Error fetching issue #{ISSUE_NUM}: {response.json()}")
break
# GET request to GitHub API
response = requests.get(
f'https://api.github.com/repos/SeattleColleges/nsc-events-nestjs/issues/{ISSUE_NUM}',
headers={'Authorization': GITHUB_ACCESS_TOKEN,
'Content-Type': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'})
issues = response.json()

issues = response.json()

# Skip if the event is a pull request
if 'pull_request' in issues:
print(f"Skipping PR #{ISSUE_NUM}. Checking next...")
ISSUE_NUM += 1 # Increment to check the next item
continue

# Process the issue
assignee = 'assignee'
try:
if issues['assignee'] is not None:
assignee = issues['assignee']['login']
else:
assignee = 'Missing assignee'
except TypeError:
assignee = 'Missing assignee'
try:
if issues['assignee'] is not None:
assignee = issues['assignee']['login']
except TypeError:
pass
title = issues['title']
repo_url = issues['repository_url']
index = issues['number']

title = issues['title']
repo_url = issues['repository_url']
index = issues['number']

# POST request to Smartsheet API
smartsheet_response = requests.post(
'https://api.smartsheet.com/2.0/sheets/3026189207687044/rows',
headers={'Authorization': f'Bearer {SMART_ACCESS_TOKEN}', 'Content-Type': 'application/json'},
json={
'sheetId': 6453502242934660,
'accessLevel': 'OWNER',
'createdBy': {'name': 'automation'},
'cells': [
{'columnId': 3135587486748548, 'displayValue': 'title', 'value': title},
{'columnId': 7639187114119044, 'displayValue': 'repo url', 'value': repo_url[45:]},
{'columnId': 6513287207276420, 'displayValue': 'assignee', 'value': assignee},
{'columnId': 4261487393591172, 'displayValue': 'index', 'value': index}
]
}
)

if smartsheet_response.status_code == 200:
print(f"Issue #{ISSUE_NUM} successfully sent to Smartsheet.")
break # Exit the loop once a valid issue is processed
else:
print(f"Failed to send issue #{ISSUE_NUM} to Smartsheet: {smartsheet_response.json()}")
break
# POST request to Smartsheet API
smartsheet_response = requests.post(
'https://api.smartsheet.com/2.0/sheets/6453502242934660/rows',
headers={'Authorization': f'Bearer {SMART_ACCESS_TOKEN}', 'Content-Type': 'application/json'},
json={
'sheetId': 6453502242934660,
'accessLevel': 'OWNER',
'createdBy': {
'name': 'automation'
},
'cells': [
{
'columnId': 3135587486748548,
'displayValue': 'title',
'value': title
},
{
'columnId': 7639187114119044,
'displayValue': 'repo url',
'value': repo_url[45:]
},
{
'columnId': 6513287207276420,
'displayValue': 'assignee',
'value': assignee
},
{
'columnId': 4261487393591172,
'displayValue': 'index',
'value': index
}
]
})

0 comments on commit d9465e7

Please sign in to comment.