Skip to content

Instantly share code, notes, and snippets.

@yezz123
Created December 29, 2022 09:09
Show Gist options
  • Save yezz123/b57ccf7ad7620116caca039749e4e41b to your computer and use it in GitHub Desktop.
Save yezz123/b57ccf7ad7620116caca039749e4e41b to your computer and use it in GitHub Desktop.
A script that check if the Github account that open an issue is new or old
import requests
import datetime
# Replace {OWNER} and {REPO} with the owner and repository where the issue is located
# Replace {ISSUE_NUMBER} with the number of the issue you want to tag
# Replace {TOKEN} with a personal access token with the necessary permissions
url = "https://api.github.com/repos/{OWNER}/{REPO}/issues/{ISSUE_NUMBER}/labels"
headers = { "Authorization": "Bearer {TOKEN}" }
# Get the account that created the issue
response = requests.get(url)
user = response.json()['user']['login']
# Check if the account is new
url = f"https://api.github.com/users/{user}"
response = requests.get(url)
created_at = response.json()['created_at']
created_at_datetime = datetime.datetime.strptime(created_at, '%Y-%m-%dT%H:%M:%SZ')
now = datetime.datetime.utcnow()
time_difference = now - created_at_datetime
if time_difference.total_seconds() < 86400:
# If the account is new, add the "under-verification" label to the issue
data = { "labels": ["under-verification"] }
response = requests.post(url, json=data, headers=headers)
if response.status_code == 201:
print("Label added successfully")
else:
print("Error adding label")
else:
print("Account is not new, no label added")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment