Netlify API Doc
https://open-api.netlify.com/
this are the three api endpoint we need
https://api.netlify.com/api/v1/sites/{site_id}/deploys
https://api.netlify.com/api/v1/sites/{site_id}/deploys/{deploy_id}
https://api.netlify.com/api/v1/deploys/{deploy_id}/cancel
Netlify Class
class Netlify(object):
def __init__(
self, netlify_site_name, netlify_api_key, netlify_site_id, netlify_webhook_id
):
...
def start_job(self):
url = f"https://api.netlify.com/build_hooks/{self.webhook_id}"
requests.post(url)
return self.list_jobs()[0]["id"]
def stop_job(self, deploy_id):
url = f"{self.base_url}/deploys/{deploy_id}/cancel"
self.make_request(url, "POST")
def get_job(self, deploy_id):
url = f"{self.base_url}/sites/{self.site_id}/deploys/{deploy_id}"
return self.make_request(url, action="GET")
def list_jobs(self):
url = f"{self.base_url}/sites/{self.site_id}/deploys"
return self.make_request(url=url, action="GET")
Wagtail admin view
amplify = Amplify(
aws_access_key_id=settings.AMPLIFY_AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AMPLIFY_AWS_SECRET_ACCESS_KEY,
app_id=settings.AMPLIFY_APP_ID,
branch_name=settings.AMPLIFY_BRANCH,
)
def netlify_jobs(request):
job_id = request.GET.get("jobid", "")
if job_id:
active_job = netlify.get_job(job_id)
jobs = netlify.list_jobs()
....
render template
def start_build(request):
jobid = netlify.start_job()
....
def stop_build(request, job_id):
netlify.stop_job(job_id)
....
Top comments (0)