Skip to content

Commit ae4bdca

Browse files
authored
Merge pull request #141 from unfoldingWord/feature-888-superdav42-only-create-on-save
Do not create user branch when working with new file
2 parents adda44b + 78b7996 commit ae4bdca

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

coverage/shields.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"message":"45.96%","label":"Integration Tests","schemaVersion":1}
1+
{"message":"45.85%","label":"Integration Tests","schemaVersion":1}

src/components/file/helpers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ export const getContentFromFile = async (file) => {
4848
} = file;
4949
let _content;
5050

51-
if (content && encoding === 'base64') {
52-
_content = decodeBase64ToUtf8(content);
51+
if (content) {
52+
if ('base64' === encoding) {
53+
_content = decodeBase64ToUtf8(content);
54+
} else {
55+
_content = content;
56+
}
5357
} else if (!content && download_url) {
5458
_content = await get({ url: download_url, noCache: true });
5559
} else if (!content && git_url) {

src/core/gitea-api/repos/contents/contents.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface ContentObject {
4040
sha: string;
4141
content: string;
4242
html_url: string;
43+
name: string;
4344
}
4445

4546
export const payload = ({
@@ -205,11 +206,15 @@ export const ensureContent = async ({
205206
throw new Error('File does not exist in default branch');
206207
}
207208

208-
} catch { // try to create the file if it doesn't exist in default or new branch
209-
// if branch does not exist yet, it will be created here.
210-
contentObject = await createContent({
211-
config, owner, repo, branch, filepath, content, message, author,
212-
});
209+
} catch {
210+
// create contentObject directly when unconnected to branch or repo.
211+
contentObject = {
212+
name: filepath.slice(filepath.lastIndexOf('/')+1),
213+
content: content || '',
214+
path: filepath,
215+
sha: 'new',
216+
html_url: '',
217+
}
213218
}
214219
}
215220

0 commit comments

Comments
 (0)