This view fetches repositories of the authenticated user from GitHub
Retrieve the access token from the session after OAuth authentication
def github_repositories(request):
access_token = request.session.get(‘github_access_token’)
# Check if the access token exists
if access_token:
# Set up the headers for GitHub API request
headers = {
'Authorization': f'Bearer {access_token}',
'Accept': 'application/vnd.github.v3+json'
}
# Make a GET request to GitHub API to fetch user repositories
response = requests.get(' https://api.github.com/orgs/ORG/repos', headers=headers)
# Check the response status code
if response.status_code == 200:
# Parse the JSON response to extract repositories
repositories = response.json()
# Pass repositories to the template
return render(request, 'dashboard.html', {'repositories': repositories})
else:
# Handle API request errors
return HttpResponse('Error fetching repositories', status=response.status_code)
else:
# Redirect the user to log in with GitHub if the access token is not found
return redirect('github_login')
iam execting solutions responses from you also you may email me through [email protected]