Skip to content

Commit 82dbbb4

Browse files
committed
chore: add explicit return types
1 parent 8259d3a commit 82dbbb4

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/proxy/processors/push-action/parsePush.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import zlib from 'zlib';
33
import fs from 'fs';
44
import path from 'path';
55
import lod from 'lodash';
6-
import { CommitContent, CommitHeader, PersonLine } from '../types';
6+
7+
import {
8+
CommitContent,
9+
CommitData,
10+
CommitHeader,
11+
PackMeta,
12+
PersonLine,
13+
} from '../types';
714
import {
815
BRANCH_PREFIX,
916
EMPTY_COMMIT_HASH,
@@ -122,7 +129,7 @@ const parsePersonLine = (line: string): PersonLine => {
122129
* @param {string[]} headerLines - The header lines of a commit.
123130
* @return {CommitHeader} An object containing the parsed commit header.
124131
*/
125-
const getParsedData = (headerLines: string[]) => {
132+
const getParsedData = (headerLines: string[]): CommitHeader => {
126133
const parsedData: CommitHeader = {
127134
parents: [],
128135
tree: '',
@@ -174,7 +181,7 @@ const getParsedData = (headerLines: string[]) => {
174181
* @return {void}
175182
* @throws {Error} If the commit header is invalid.
176183
*/
177-
const validateParsedData = (parsedData: CommitHeader) => {
184+
const validateParsedData = (parsedData: CommitHeader): void => {
178185
const missing = [];
179186
if (parsedData.tree === '') {
180187
missing.push('tree');
@@ -202,9 +209,9 @@ const isBlankPersonLine = (personLine: PersonLine): boolean => {
202209
/**
203210
* Parses the commit data from the contents of a pack file.
204211
* @param {CommitContent[]} contents - The contents of the pack file.
205-
* @return {Array} An array of commit data objects.
212+
* @return {CommitData[]} An array of commit data objects.
206213
*/
207-
const getCommitData = (contents: CommitContent[]) => {
214+
const getCommitData = (contents: CommitContent[]): CommitData[] => {
208215
console.log({ contents });
209216
return lod
210217
.chain(contents)
@@ -253,9 +260,9 @@ const getCommitData = (contents: CommitContent[]) => {
253260
/**
254261
* Gets the metadata from a pack file.
255262
* @param {Buffer} buffer - The buffer containing the pack file data.
256-
* @return {Array} An array containing the metadata and the remaining buffer.
263+
* @return {[PackMeta, Buffer]} An array containing the metadata and the remaining buffer.
257264
*/
258-
const getPackMeta = (buffer: Buffer) => {
265+
const getPackMeta = (buffer: Buffer): [PackMeta, Buffer] => {
259266
const sig = buffer.slice(0, PACKET_SIZE).toString('utf-8');
260267
const version = buffer.readUIntBE(PACKET_SIZE, PACKET_SIZE);
261268
const entries = buffer.readUIntBE(PACKET_SIZE * 2, PACKET_SIZE);
@@ -273,9 +280,9 @@ const getPackMeta = (buffer: Buffer) => {
273280
* Gets the contents of a pack file.
274281
* @param {Buffer} buffer - The buffer containing the pack file data.
275282
* @param {number} entries - The number of entries in the pack file.
276-
* @return {CommitContent[]} An array of commit content objects.
283+
* @return {Array} An array of commit content objects.
277284
*/
278-
const getContents = (buffer: Buffer | CommitContent[], entries: number) => {
285+
const getContents = (buffer: Buffer | CommitContent[], entries: number): CommitContent[] => {
279286
const contents = [];
280287

281288
for (let i = 0; i < entries; i++) {
@@ -295,7 +302,7 @@ const getContents = (buffer: Buffer | CommitContent[], entries: number) => {
295302
* @param {boolean[]} bits - The array of bits.
296303
* @return {number} The integer value.
297304
*/
298-
const getInt = (bits: boolean[]) => {
305+
const getInt = (bits: boolean[]): number => {
299306
let strBits = '';
300307

301308
// eslint-disable-next-line guard-for-in
@@ -312,7 +319,7 @@ const getInt = (bits: boolean[]) => {
312319
* @param {Buffer} buffer - The buffer containing the pack file data.
313320
* @return {Array} An array containing the content object and the next buffer.
314321
*/
315-
const getContent = (item: number, buffer: Buffer) => {
322+
const getContent = (item: number, buffer: Buffer): [CommitContent, Buffer] => {
316323
// FIRST byte contains the type and some of the size of the file
317324
// a MORE flag -8th byte tells us if there is a subsequent byte
318325
// which holds the file size
@@ -383,7 +390,7 @@ const getContent = (item: number, buffer: Buffer) => {
383390
* @param {Buffer} buf - The buffer containing the zipped content.
384391
* @return {Array} An array containing the unzipped content and the size of the deflated content.
385392
*/
386-
const unpack = (buf: Buffer) => {
393+
const unpack = (buf: Buffer): [string, number] => {
387394
// Unzip the content
388395
const inflated = zlib.inflateSync(buf);
389396

src/proxy/processors/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@ export type CommitHeader = {
3131
author: PersonLine;
3232
committer: PersonLine;
3333
}
34+
35+
export type CommitData = {
36+
tree: string;
37+
parent: string;
38+
author: string;
39+
committer: string;
40+
authorEmail: string;
41+
commitTimestamp: string;
42+
message: string;
43+
}
44+
45+
export type PackMeta = {
46+
sig: string;
47+
version: number;
48+
entries: number;
49+
}

0 commit comments

Comments
 (0)