Skip to content

Instantly share code, notes, and snippets.

@Aveline-art
Last active January 4, 2024 09:40
Show Gist options
  • Save Aveline-art/fa5e50998e5dbaa11f0bdc11be010229 to your computer and use it in GitHub Desktop.
Save Aveline-art/fa5e50998e5dbaa11f0bdc11be010229 to your computer and use it in GitHub Desktop.
A program that creates an issue and pull request in a repository. Useful to test GHAs.
import requests
import json
import time
print('sleeping for 10 secs')
time.sleep(10)
link = 'https://api.github.com/repos/{INSERT_NAME_OF_OWNER}/{INSERT_NAME_OF_REPO}/issues'
headers = {
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'token {INSERT_API_KEY_HERE}'
}
r1 = requests.post('https://api.github.com/repos/{INSERT_NAME_OF_OWNER}/{INSERT_NAME_OF_REPO}/issues', headers = headers, json = {
'title': 'this is a test',
'body': 'this is a body',
})
print(r1.status_code)
r2 = requests.patch(json.loads(r1.text)['url'], headers = headers, json = {
'state': 'closed',
})
print(r2.status_code)
r3 = requests.post('https://api.github.com/repos/{INSERT_NAME_OF_OWNER}/{INSERT_NAME_OF_REPO}/pulls', headers = headers, json = {
'title': 'this is a test',
'body': 'this is a body',
'head': 'main',
'base': {INSERT_NAME_OF_A_BRANCH},
})
print(r3.status_code)
r4 = requests.patch(json.loads(r3.text)['url'], headers = headers, json = {
'state': 'closed',
})
print(r4.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment