Open barnettwilliam opened 8 months ago
I suspect that the problem here might be that when creating the commit on GitHub, we need to provide the parent SHA. We currently do this by storing that SHA in the panel and providing it at the time of saving, but we do not update this SHA when a panel has been saved. As a result, the second save attempts to create a commit in a branch but that commit doesn't have the current branch HEAD as its parent. I suspect GitHub doesn't like that :-)
In fact, storing the SHA in the panel is wrong, it should really be a property of the platform -- or even be retrieved afresh as we create the commit.
Looking at https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28 I think it's clear that my suspicion above is valid. The correct approach would be not to save the SHA in the panel at all but to instead pick up the current SHA in FileManager#storeFile
before actually creating a commit. This needs to manage the situation where the file doesn't actually exist in the repository yet. Once we implement support for #140, we will simply use the HEAD
SHA for the branch that we're saving to.
One thing to watch out for: what if I am a little forgetful, and I have the same activity open from multiple tabs? If the client is completely unaware of SHA1s, this could happen:
It may be worth for the tab to submit a request saying "I want to add this content on top of commit X", and the backend saying "yes, commit X is the latest, I have saved, here is the new SHA1", or "no, commit X is not the latest anymore, user should be shown a warning and be asked to either reload or confirm they want to overwrite their changes".
When a user clicks the save button for a second time an error is reported by a red popover box. It appears to be for the panel that the change was made. Seen during the MDNet symposium demo.
The error log from Chrome on the error being reported: