File size: 4,841 Bytes
21dd449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
export interface ApiLfsBatchRequest {
	/// github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
	operation: "download" | "upload";
	transfers?: string[];
	/**
	 * Optional object describing the server ref that the objects belong to. Note: Added in v2.4.
	 *
	 * We use this object for QOL and to fail early for users when they're trying to push to the wrong reference.
	 * But it does nothing for security.
	 */
	ref?: {
		name: string;
	} | null;
	objects: {
		oid: string;
		/**
		 * Integer byte size of the LFS object. Must be at least zero.
		 */
		size: number;
	}[];
	/**
	 * The hash algorithm used to name Git LFS objects. Optional; defaults to sha256 if not specified.
	 * */
	hash_algo?: string;
}

export interface ApiLfsBatchResponse {
	transfer?: ApiLfsResponseTransfer;
	objects: ApiLfsResponseObject[];
}

export type ApiLfsResponseTransfer = "basic" | "multipart";

export interface ApiLfsCompleteMultipartRequest {
	oid: string;
	parts: { etag: string; partNumber: number }[];
}

export interface ApiLfsResponseObject {
	/**
	 * Optional boolean specifying whether the request
	 * for this specific object is authenticated.
	 * If omitted or false, Git LFS will attempt to find credentials for this URL.
	 */
	authenticated?: boolean;
	oid: string;
	/**
	 * Integer byte size of the LFS object. Must be at least zero.
	 */
	size: number;
	/**
	 * Applicable actions depend on which `operation` is specified in the request.
	 * How these properties are interpreted depends on which transfer adapter
	 * the client will be using.
	 */
	actions?: {
		/**
		 * Download operations MUST specify a download action,
		 * or an object error if the object cannot be downloaded for some reason
		 */
		download?: ApiLfsAction;
		/**
		 * Upload operations can specify an upload and a verify action.
		 * The upload action describes how to upload the object.
		 */
		upload?: ApiLfsAction;
		/**
		 * The LFS client will hit this URL after a successful upload.
		 * Servers can use this for extra verification, if needed.
		 */
		verify?: ApiLfsAction;
	};
	/**
	 * If there are problems accessing individual objects, servers should continue
	 * to return a 200 status code, and provide per-object errors
	 */
	error?: {
		code: number;
		message: string;
	};
}

export interface ApiLfsAction {
	href: string;
	/**
	 * Optional hash of String HTTP header key/value pairs to apply to the request
	 */
	header?: { [key: string]: string } & { chunk_size?: string };
	/**
	 * Whole number of seconds after local client time when transfer will expire.
	 * Preferred over `expires_at` if both are provided.
	 * Maximum of 2147483647, minimum of -2147483647.
	 */
	expires_in?: number;
	/**
	 * String uppercase RFC 3339-formatted timestamp with second precision
	 * for when the given action expires (usually due to a temporary token).
	 */
	expires_at?: string;
}

export interface ApiPreuploadRequest {
	/**
	 * Optional, otherwise takes the existing content of `.gitattributes` for the revision.
	 *
	 * Provide this parameter if you plan to modify `.gitattributes` yourself at the same
	 * time as uploading LFS files.
	 *
	 * Note that this is not needed if you solely rely on automatic LFS detection from HF: the commit endpoint
	 * will automatically edit the `.gitattributes` file to track the files passed to its `lfsFiles` param.
	 */
	gitAttributes?: string;
	files: Array<{
		/**
		 * Path of the LFS file
		 */
		path: string;
		/**
		 * Full size of the LFS file
		 */
		size: number;
		/**
		 * Base64-encoded sample of the first 512 bytes of the file
		 */
		sample: string;
	}>;
}

export interface ApiPreuploadResponse {
	files: Array<{
		path: string;
		uploadMode: "lfs" | "regular";
	}>;
}

export interface ApiCommitHeader {
	summary: string;
	description?: string;
	/**
	 * Parent commit. Optional
	 *
	 * - When opening a PR: will use parentCommit as the parent commit
	 * - When committing on a branch: Will make sure that there were no intermediate commits
	 */
	parentCommit?: string;
}

export interface ApiCommitDeletedEntry {
	path: string;
}

export interface ApiCommitLfsFile {
	path: string;
	oldPath?: string;
	/** Required if {@link oldPath} is not set */
	algo?: "sha256";
	/** Required if {@link oldPath} is not set */
	oid?: string;
	size?: number;
}

export interface ApiCommitFile {
	/** Required if {@link oldPath} is not set */
	content?: string;
	path: string;
	oldPath?: string;
	encoding?: "utf-8" | "base64";
}

export type ApiCommitOperation =
	| {
			key: "file";
			value: ApiCommitFile;
	  }
	| {
			key: "lfsFile";
			value: ApiCommitLfsFile;
	  }
	| {
			key: "deletedFile";
			value: ApiCommitDeletedEntry;
	  };

export interface ApiCommitData {
	id: string;
	title: string;
	message: string;
	authors: Array<{ user: string; avatar: string }>;
	date: string;
	formatted?: string;
}