I am attempting to utilize octokit/rest
in order to programmatically remove a directory. Below is the code I am using:
import {Octokit as Github} from '@octokit/rest';
const githubToken = "read from vault";
// Functions for retrieving current commit, creating new commit, setting branch to commit,
// getting directory SHA, and deleting from repository
export const deleteDirectoryFromGithubRepo = async (
directoryName: string
) => {
// Code logic here...
}
Upon calling deleteDirectoryFromGithubRepo
, it creates an empty commit on GitHub. This means that a commit is made without any changes.
I have researched that passing the current commit may be causing the deleted files to be restored. However, removing it results in an error message saying Update is not a fast forward
.
Full response from GitHub:
{
"name": "HttpError",
"status": 422,
"response": {
"url": "https://api.github.com/repos/myOrg/myRepo/git/refs/heads%2Fmain",
"status": 422,
"headers": {
"header1": "*",
"header2": "*"
},
"data": {
"message": "Update is not a fast forward",
"documentation_url": "https://docs.github.com/rest/reference/git#update-a-reference"
}
},
"request": {
"method": "PATCH",
"url": "https://api.github.com/repos/myOrg/myRepo/git/refs/heads%2Fmain",
"headers": {
"accept": "application/vnd.github.v3+json",
"user-agent": "octokit-rest.js/18.12.0 octokit-core.js/3.6.0 Node.js/14.19.3 (linux; x64)",
"authorization": "token [REDACTED]",
"content-type": "application/json; charset=utf-8"
},
"body": "{\"sha\":\"75dd3**************ee3da188d4\"}",
"request": {}
}
}
The version of octokit-rest.js
being used is 18.12.0
.
Do you have any suggestions on how to resolve this issue?