-
-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception('Could not retrieve diff. Operation will abort.') #231
Comments
Getting the same issue, config is:
Based on logs, repo checks out fine. This is a private repo, but token should be working for access, as it does clone down just fine. I did try it on a separate public repo, and it worked without issue, the exact same format, so I suspect its related to privacy somehow but I'm not sure how. |
@CermakM @cmathewsendsight Please could you try removing |
I will try that this morning and report back :) |
Same result |
In that case I'm not 100% sure. Do you own the private repo? I've tested it on a private repo and it should work with them, but there might be some permissions issues. You shouldn't need to specify
If none of that works, try creating a classic Personal Access Token with the |
Created a new branch, and new PR. This is my action now:
It succeeds when running against the commit (note, I've removed the branches- |
Thanks for the info. I just noticed that the action was targeting an old image, and that may have caused a few issues. It might not resolve your problem, but could you try anyway to rule that out? You just need to use the latest version. 😄 If that doesn’t help I’ll look into it further. Thanks. |
I'm on the latest version and having the problem running the Action from PR in a Private Repo as well with the same error.
Though, my action file is even more simple.
Hope this provides @alstr a bit more context. |
same issue here name: Check for TODO comments
on:
workflow_dispatch:
pull_request:
jobs:
check_todos:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: 'TODO to Issue'
uses: 'alstr/[email protected]'
with:
INSERT_ISSUE_URLS: 'true'
- name: Set Git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and Push Changes
run: |
git add -A
if [[ `git status --porcelain` ]]; then
git commit -m "Automatically added GitHub issue links to TODOs"
git push origin main
else
echo "No changes to commit"
fi |
I've just created a test private repo with nothing other than the standard workflow file and a simple Python file and it worked fine for me. That would lead me to think it may be permissions related, but more than likely if the common thread here is the The diff can fail to be retrieved if the commit references it is trying to compare are invalid (e.g., one doesn't exist). This can happen in certain circumstances. I'll shamelessly copy in @rgalonso in case he has any thoughts. |
I don't have a strong reason for saying so, but I suspect that the Making the exception's message more verbose will probably help us run this to ground. The following change should help us resolve both this issue and any related issues in the future: - raise Exception('Could not retrieve diff. Operation will abort.')
+ error_response = [f"Could not retrieve diff",
+ f'URL: {diff_url}',
+ f'Status code: {diff_request.status_code}']
+ if 'application/json' in diff_request.headers['content-type']:
+ error_response.append(f"Server response: {json.loads(diff_request.text)['message']}")
+ error_response.append('Operation will abort')
+ raise Exception('\n'.join(error_response)) |
Sounds like a plan. I've released a new update with the updated error logging. I actually noticed it when I was in the process of updating the action: https://github.com/alstr/todo-to-issue-action/actions/runs/12204165092/job/34048676326
The problem here being the SHA |
Yes, that's exactly what I was wondering might be the case. The "before" SHA may no longer exist if a force push removed it from the history. Those of you seeing this issue: did anyone of you force push the commit in question? |
I can't remember the exact sequence of events, but yes it might be the force push that caused it in my case. If this exception occurs - which might be hard to anticipate if it is due to a force push and a nonexistent SHA - we could fall back to trying this endpoint instead:
That would retrieve the diff for the last commit, rather than trying to compare two specific commits, but it might be a viable option. |
You might want to make sure GitHub hasn't changed the API implementation. I can't seem to find it now, but the other day when was looking at this I read some doc which said the |
I've not seen that myself but it's potentially the case. What if we cover all bases with a change like |
Unclear whether it's a string or not, and how that would end up being represented once having passed through That said, given your earlier comment, I'm not convinced that's good enough. Perhaps some logic needs to be added based on the |
Okay, I figured out the problem. When the action is triggered by a PR, this supplies the diff URL automatically in the form https://github.com/alstr/todo-to-issue-action-test/pull/2.diff. If you paste this in your browser, it triggers a redirect to https://patch-diff.githubusercontent.com/raw/alstr/todo-to-issue-action-test/pull/2.diff?token=mytoken. When the action tries to request this URL though, it returns a 404. What I've done is extract the PR number from the supplied URL and rebuild the diff URL utilising the That then allows it to retrieve the diff in question. I've tested it and it should work. Obviously if you have multiple workflow triggers, you may want to refine that so you're not getting duplicate issues created. |
Good find. Hopefully that resolves the issue for everyone who was reporting this.
That's a pretty important note. I don't know if that point is already covered by the README, but maybe it's worth saying there. |
Yeah, I've added it in a couple of places to make it clearer. I still notice the error when force pushing, so it might be worth adding the fallback to the |
(I've added the fallback URL and it functioned as expected here after a force push: https://github.com/alstr/todo-to-issue-action/actions/runs/12300435860/job/34328590758) |
I am hitting this issue with v5 as well, even tho its explicitly stated the
TOKEN
is not required and would default togithub.token
:This is my current configuration:
I tried adding also
permissions
field but to no affect. My settings are set correctly to allow READ and WRITE. Any idea what' wrong?The text was updated successfully, but these errors were encountered: