Skip to content

Commit

Permalink
feat: file mode option (#80)
Browse files Browse the repository at this point in the history
By default, the file mode for a file is 100644.  An user can specify
the file mode in addition to the content and the encoding.

Co-authored-by: Luca Lanziani <luca@lanziani.com>
  • Loading branch information
kennethzfeng and LucaLanziani committed Oct 19, 2021
1 parent 2577331 commit 682ea7b
Show file tree
Hide file tree
Showing 5 changed files with 1,149 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ octokit
.toString("utf-8")
.toUpperCase();
},
"path/to/file5.sh": {
content: "echo Hello World",
encoding: "utf-8",
// one of the modes supported by the git tree object
// https://developer.github.com/v3/git/trees/#tree-object
mode: "100755",
},
},
commit:
"creating file1.txt, file2.png, deleting file3.txt, updating file4.txt (if it exists)",
"creating file1.txt, file2.png, deleting file3.txt, updating file4.txt (if it exists), file5.sh",
},
],
})
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Changes = {
export type File = {
content: string;
encoding: "utf-8" | "base64";
mode?: string;
};

export type UpdateFunctionFile =
Expand Down
10 changes: 8 additions & 2 deletions src/value-to-tree-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ export async function valueToTreeObject(
path: string,
value: string | File
) {
let mode = "100644";
if (value !== null && typeof value !== "string") {
mode = value.mode || mode;
}

// Text files can be changed through the .content key
if (typeof value === "string") {
return {
path,
mode: "100644",
mode: mode,
content: value,
};
}
Expand All @@ -28,9 +33,10 @@ export async function valueToTreeObject(
}
);
const blobSha = data.sha;

return {
path,
mode: "100644",
mode: mode,
sha: blobSha,
};
}

0 comments on commit 682ea7b

Please sign in to comment.