/gitgrep2csv

Turn grep results into a csv with git information on that file / commit

Primary LanguageTypeScript

gitgrep2csv

Turn grep results into a csv with git information on that file / commit

Usage

$ grep -n foo | gitgrep2csv

Interface: Config

Configuration for a run

Properties

appEnv

Optional appEnv: string

Defined in

types.d.ts:64


appName

appName: string

Defined in

types.d.ts:63


input

Optional input: any

Defined in

types.d.ts:65


loadDotEnv

Optional loadDotEnv: boolean | Function

Defined in

types.d.ts:66


markdown

markdown: boolean

Defined in

types.d.ts:67


multilineSep

Optional multilineSep: null | string | RegExp

Defined in

types.d.ts:68


process

Optional process: any

Defined in

types.d.ts:71


semgrep

semgrep: boolean

Defined in

types.d.ts:69


sep

sep: string

Defined in

types.d.ts:70

Interface: GitBlame

A single commit & single file's parsed Git Blame

Hierarchy

Properties

author

author: string

Git author of this blame.

Inherited from

GitBlameBase.author

Defined in

types.d.ts:85


authorEmail

authorEmail: string

Git author email of this blame.

Inherited from

GitBlameBase.authorEmail

Defined in

types.d.ts:89


authorTime

authorTime: Date

Author time of this blame.

Inherited from

GitBlameBase.authorTime

Defined in

types.d.ts:93


authorTz

Optional authorTz: number

Timezone of author date

Defined in

types.d.ts:123


committer

committer: string

Committer name of this blame.

Inherited from

GitBlameBase.committer

Defined in

types.d.ts:97


committerEmail

committerEmail: string

Committer email of this blame.

Inherited from

GitBlameBase.committerEmail

Defined in

types.d.ts:101


committerTime

committerTime: Date

Committer time of this blame.

Inherited from

GitBlameBase.committerTime

Defined in

types.d.ts:105


committerTz

Optional committerTz: number

Timezone of committer date

Defined in

types.d.ts:127


lines

Optional lines: number[]

Lines of file this blame applies to

Defined in

types.d.ts:131


previous

Optional previous: string

Previous sha of this blame.

Inherited from

GitBlameBase.previous

Defined in

types.d.ts:109


rev

rev: string

revision-sha of this blame.

Inherited from

GitBlameBase.rev

Defined in

types.d.ts:81


summary

summary: string

Summary text for this blame.

Inherited from

GitBlameBase.summary

Defined in

types.d.ts:113

Interface: GitBlameBase

Common "blame" information shared by either a line-by-line style git-blame, or by a merge commit.

Hierarchy

Properties

author

author: string

Git author of this blame.

Defined in

types.d.ts:85


authorEmail

authorEmail: string

Git author email of this blame.

Defined in

types.d.ts:89


authorTime

authorTime: Date

Author time of this blame.

Defined in

types.d.ts:93


committer

committer: string

Committer name of this blame.

Defined in

types.d.ts:97


committerEmail

committerEmail: string

Committer email of this blame.

Defined in

types.d.ts:101


committerTime

committerTime: Date

Committer time of this blame.

Defined in

types.d.ts:105


previous

Optional previous: string

Previous sha of this blame.

Defined in

types.d.ts:109


rev

rev: string

revision-sha of this blame.

Defined in

types.d.ts:81


summary

summary: string

Summary text for this blame.

Defined in

types.d.ts:113

Interface: GitMerge

Blame information for a git merge, typically parsed from Github format PR messages.

Hierarchy

Properties

author

author: string

Git author of this blame.

Inherited from

GitBlameBase.author

Defined in

types.d.ts:85


authorEmail

authorEmail: string

Git author email of this blame.

Inherited from

GitBlameBase.authorEmail

Defined in

types.d.ts:89


authorTime

authorTime: Date

Author time of this blame.

Inherited from

GitBlameBase.authorTime

Defined in

types.d.ts:93


branch

Optional branch: string

Branch name, parsed from summary.

Defined in

types.d.ts:149


committer

committer: string

Committer name of this blame.

Inherited from

GitBlameBase.committer

Defined in

types.d.ts:97


committerEmail

committerEmail: string

Committer email of this blame.

Inherited from

GitBlameBase.committerEmail

Defined in

types.d.ts:101


committerTime

committerTime: Date

Committer time of this blame.

Inherited from

GitBlameBase.committerTime

Defined in

types.d.ts:105


parent

parent: string[]

The parent commits for this merge

Defined in

types.d.ts:141


pr

Optional pr: number

Pull request number, parsed from summary.

Defined in

types.d.ts:145


previous

Optional previous: string

Previous sha of this blame.

Inherited from

GitBlameBase.previous

Defined in

types.d.ts:109


rev

rev: string

revision-sha of this blame.

Inherited from

GitBlameBase.rev

Defined in

types.d.ts:81


summary

summary: string

Summary text for this blame.

Inherited from

GitBlameBase.summary

Defined in

types.d.ts:113

Interface: Match

A grep match. Listed vaguely in order of display in csv,

Properties

commits

Optional commits: Record<string, GitBlame>

All commits found for this match, by sha.

Defined in

types.d.ts:34


head

head: string

Current rev this project is on.

Defined in

types.d.ts:46


lineEnd

lineEnd: number

Line where this match ends.

Defined in

types.d.ts:30


lineStart

lineStart: number

Line where this match starts.

Defined in

types.d.ts:26


matchedPath

matchedPath: string

Path that grep found for this match.

Defined in

types.d.ts:9


matches

Optional matches: number[]

List of exact line numbers where there is a match. Since lineStart & lineEnd might include --before, --after, --context grep context.

Defined in

types.d.ts:52


merges

Optional merges: Record<string, GitMerge>

All prs found for this match, by sha.

Defined in

types.d.ts:38


path

path: string

Path of file inside the project for this match.

Defined in

types.d.ts:22


project

project: string

Project directory name for this match.

Defined in

types.d.ts:18


rootDir

rootDir: string

Directory where we found this project

Defined in

types.d.ts:56


text

text: string

Text of this match.

Defined in

types.d.ts:13


vars

Optional vars: Record<string, string>

Any free-variables captured by semgrep.

Defined in

types.d.ts:42

API

Interfaces

Variables

appName

appName: string = "gitgrep"

Assign a name, primarily to use for env variable prefix

Defined in

config.ts:17


headerTitles

Const headerTitles: string[]

Defined in

csv.ts:21


helper

Const helper: Object

Type declaration

Name Type
streams __module

Defined in

index.ts:11


initialDefaults

Const initialDefaults: Readonly<Config>

For reference, a copy of the startup defaults

Defined in

config.ts:60


input

input: ReadInput | undefined = "-"

Source to read. Defaults to - for stdin.

Defined in

config.ts:21


loadDotEnv

loadDotEnv: boolean | Function

Whether to load dotenv or a function to load it

Defined in

config.ts:25


markdown

markdown: boolean = false

Whether to output in markdown

Defined in

config.ts:29


multilineSep

multilineSep: string = ""

Seperator for multi-line code blocks

Defined in

config.ts:33


semgrep

semgrep: boolean = false

Expect semgrep json input

Defined in

config.ts:37


sep

sep: string = "\t"

Separator for output csv

Defined in

config.ts:41

Functions

argsConfig

argsConfig(args?, base?): Config

Get config from args & env

Parameters

Name Type Default value
args string[] []
base Partial<Config> undefined

Returns

Config

Defined in

config.ts:89


csv

csv(c): (source: AsyncIterable<Match>) => AsyncGenerator<string, void, unknown>

Extra & write csv data

Parameters

Name Type
c Config

Returns

fn

▸ (source): AsyncGenerator<string, void, unknown>

Parameters
Name Type
source AsyncIterable<Match>
Returns

AsyncGenerator<string, void, unknown>

Defined in

csv.ts:170


defaults

defaults(base?): Config

Populate a Config with defaults.

Parameters

Name Type
base? Partial<Config>

Returns

Config

Defined in

config.ts:46


gitBlame

gitBlame(source): AsyncIterable<Partial<Match>>

Parameters

Name Type
source AsyncIterable<Partial<Match>>

Returns

AsyncIterable<Partial<Match>>

Defined in

streams.ts:44


gitHead

gitHead(): (source: AsyncIterable<Partial<Match>>) => AsyncGenerator<Partial<Match>, void, unknown>

Attach the sha of main branch

Returns

fn

▸ (source): AsyncGenerator<Partial<Match>, void, unknown>

Parameters
Name Type
source AsyncIterable<Partial<Match>>
Returns

AsyncGenerator<Partial<Match>, void, unknown>

Defined in

git.ts:229


gitProject

gitProject(source): AsyncIterable<Partial<Match>>

Parameters

Name Type
source AsyncIterable<Partial<Match>>

Returns

AsyncIterable<Partial<Match>>

Defined in

streams.ts:44


githubPr

githubPr(source): AsyncIterable<Partial<Match>>

Parameters

Name Type
source AsyncIterable<Partial<Match>>

Returns

AsyncIterable<Partial<Match>>

Defined in

streams.ts:44


lines

lines(source, split?): AsyncGenerator<string, void, unknown>

Process an async-iterator of strings, splitting it on newlines

Parameters

Name Type Default value
source AsyncIterable<string> undefined
split RegExp newlines

Returns

AsyncGenerator<string, void, unknown>

Defined in

lines.ts:8


loadDotEnvOnce

loadDotEnvOnce(): void

Default strategy to load dotenv first time only.

Returns

void

Defined in

config.ts:80


md

md(c): (source: AsyncIterable<Match>) => AsyncGenerator<string, void, unknown>

Parameters

Name Type
c Config

Returns

fn

▸ (source): AsyncGenerator<string, void, unknown>

Parameters
Name Type
source AsyncIterable<Match>
Returns

AsyncGenerator<string, void, unknown>

Defined in

csv.ts:200


multilineGroup

multilineGroup(c): <I>(source: I) => I | (lines: AsyncIterable<string>) => AsyncGenerator<string[], void, unknown>

Batch lines together until a config.multilineSep appears Or pass through if no multilineSep configured

Parameters

Name Type
c Config

Returns

<I>(source: I) => I | (lines: AsyncIterable<string>) => AsyncGenerator<string[], void, unknown>

Defined in

group.ts:8


parse

parse(c): (source: AsyncIterable<string | string[]>) => AsyncIterable<Partial<Match>>

Parameters

Name Type
c Config

Returns

fn

▸ (source): AsyncIterable<Partial<Match>>

Parameters
Name Type
source AsyncIterable<string | string[]>
Returns

AsyncIterable<Partial<Match>>

Defined in

parse.ts:25


parseSemgrep

parseSemgrep(source): AsyncGenerator<Partial<Match>, void, unknown>

Parameters

Name Type
source AsyncIterable<string>

Returns

AsyncGenerator<Partial<Match>, void, unknown>

Defined in

parse.ts:119


parseSemgrepMatch

parseSemgrepMatch(semgrep): Promise<Partial<Match>>

Parse semgrep json input lines

Parameters

Name Type
semgrep Record<string, any>

Returns

Promise<Partial<Match>>

Defined in

parse.ts:88


processConfig

processConfig(p?, c?): Config

Parameters

Name Type Default value
p Process process
c? Partial<Config> undefined

Returns

Config

Defined in

config.ts:144


reloadDotEnv

reloadDotEnv(): void

Strategy for always reloading dotenv. Can be useful if config might change & wants freshened.

Returns

void

Defined in

config.ts:71


tabsToSpaces

tabsToSpaces(source): AsyncIterable<string>

Parameters

Name Type
source AsyncIterable<string>

Returns

AsyncIterable<string>

Defined in

streams.ts:44


tabsToSpacesTransform

tabsToSpacesTransform(m): string

Parameters

Name Type
m string

Returns

string

Defined in

lines.ts:42