Skip to content

Commit 8358cb9

Browse files
committed
Add GitData to Manifest for auditing
1 parent 1b7c4cd commit 8358cb9

File tree

9 files changed

+106
-12
lines changed

9 files changed

+106
-12
lines changed

src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class ApiHandler {
9898
ref: manifest.ref,
9999
shortSha: manifest.shortSha,
100100
site: manifest.site,
101+
commit: manifest.commit,
101102
};
102103
}
103104
}

src/commands/upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class UploadCommand {
8181
const manifestObj = new manifest.Manifest(
8282
(site as string) || 'default',
8383
this.options.ref || gitData.ref,
84-
this.options.branch || gitData.branch || ''
84+
this.options.branch || gitData.branch || '',
85+
gitData.commit
8586
);
8687
await manifestObj.createFromDirectory(path);
8788
if (config.redirectTrailingSlashes === false) {

src/gitdata.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import git = require('isomorphic-git');
22
import fs = require('fs');
33

4-
export async function getGitData(path: string) {
4+
import * as manifest from './manifest';
5+
interface GitData {
6+
ref: string;
7+
branch: string;
8+
commit: manifest.Commit;
9+
}
10+
11+
export async function getGitData(path: string): Promise<GitData> {
512
const root = await git.findRoot({
613
fs,
714
filepath: path,
815
});
9-
const commits = await git.log({
16+
const log = await git.log({
1017
fs,
1118
dir: root,
1219
depth: 1,
@@ -19,9 +26,22 @@ export async function getGitData(path: string) {
1926
fs,
2027
dir: root,
2128
fullname: false,
22-
}));
29+
})) ||
30+
'';
31+
if (!log || !log[0]) {
32+
throw new Error(`Failed to retrieve Git data from path: ${path}`);
33+
}
34+
const commit = log[0].commit;
35+
const cleanMessage = commit.message.slice(0, 128);
2336
return {
24-
ref: commits && commits[0].oid,
37+
ref: log[0].oid,
2538
branch: branch,
39+
commit: {
40+
message: cleanMessage,
41+
author: {
42+
name: commit.author.name,
43+
email: commit.author.email,
44+
},
45+
},
2646
};
2747
}

src/manifest.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export interface Redirect {
3131
permanent?: boolean;
3232
}
3333

34+
interface GitAuthor {
35+
email: string;
36+
name: string;
37+
}
38+
39+
export interface Commit {
40+
message: string;
41+
author: GitAuthor;
42+
}
43+
3444
export interface SerializedManifest {
3545
site: string;
3646
ref: string;
@@ -42,20 +52,22 @@ export interface SerializedManifest {
4252
redirectTrailingSlashes: boolean;
4353
localizationPathFormat: string;
4454
headers: Record<string, Record<string, string>>;
55+
commit: Commit;
4556
}
4657

4758
export class Manifest {
4859
site: string;
4960
ref: string;
50-
branch?: string;
61+
branch: string;
5162
files: ManifestFile[];
5263
redirects: Redirect[];
5364
shortSha: string;
5465
redirectTrailingSlashes: boolean;
5566
localizationPathFormat: string;
5667
headers: Record<string, Record<string, string>>;
68+
commit: Commit;
5769

58-
constructor(site: string, ref: string, branch?: string) {
70+
constructor(site: string, ref: string, branch: string, commit: Commit) {
5971
this.files = [];
6072
this.redirects = [];
6173
this.site = site;
@@ -65,6 +77,7 @@ export class Manifest {
6577
this.redirectTrailingSlashes = true;
6678
this.localizationPathFormat = DEFAULT_LOCALIZATION_PATH_FORMAT;
6779
this.headers = {};
80+
this.commit = commit;
6881
}
6982

7083
async createFromDirectory(path: string) {

src/static/webui.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<title>Fileset</title>
66
<link rel="preconnect" href="https://fonts.gstatic.com">
7-
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;600&display=swap" rel="stylesheet">
7+
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;600;700&display=swap" rel="stylesheet">
88
<link rel="stylesheet" href="/fileset/static/webui.min.css">
99
</head>
1010
<body>

src/upload.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ export async function uploadManifest(
7777
? manifest.files
7878
: await findUploadedFiles(manifest, storageBucket);
7979
const numTotalFiles = filesToUpload.length;
80-
console.log(
81-
`Found new ${filesToUpload.length} files out of ${manifest.files.length} total...`
82-
);
8380

8481
if (numTotalFiles <= 0) {
82+
console.log('No new files to upload. Updating the manifest...');
8583
await finalize(googleCloudProject, manifest, ttl);
8684
} else {
85+
console.log(
86+
`Found ${numTotalFiles} new files out of ${manifest.files.length} total...`
87+
);
8788
let bytesTransferred = 0;
8889
let numProcessedFiles = 0;
8990
const startTime = Math.floor(Date.now() / 1000);
@@ -146,6 +147,7 @@ async function saveManifestEntity(
146147
const ent = {
147148
key: key,
148149
excludeFromIndexes: [
150+
'commit',
149151
'headers',
150152
'localizationPathFormat',
151153
'paths',
@@ -184,6 +186,7 @@ async function finalize(
184186
redirectTrailingSlashes: manifest.redirectTrailingSlashes,
185187
ref: manifest.ref,
186188
site: manifest.site,
189+
commit: manifest.commit,
187190
});
188191

189192
// Create branch mapping, so a branch name can be used to lookup filesets.
@@ -204,6 +207,7 @@ async function finalize(
204207
redirectTrailingSlashes: manifest.redirectTrailingSlashes,
205208
ref: manifest.ref,
206209
site: manifest.site,
210+
commit: manifest.commit,
207211
});
208212
}
209213

src/webui/pages/buildpage.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Link} from 'preact-router/match';
44
import {Loading} from '../components/loading';
55
import {Page} from './page';
66
import {createStagingLink} from '../utils/links';
7+
import {prettyDate} from '../utils/formatters';
78
import {rpc} from '../utils/rpc';
89

910
interface BuildPageProps {
@@ -146,6 +147,39 @@ export class BuildPage extends Page<BuildPageProps, BuildPageState> {
146147
);
147148
}
148149

150+
renderGitData() {
151+
return (
152+
<div>
153+
{this.state.manifest && this.state.manifest.commit ? (
154+
<div class="BuildPage__content__gitData">
155+
<div class="BuildPage__content__gitData__primary">
156+
<span
157+
class="BuildPage__content__gitData__primary__author"
158+
title="{this.state.manifest.commit.author.email}"
159+
>
160+
{this.state.manifest.commit.author.name}
161+
</span>
162+
<span class="BuildPage__content__gitData__primary__message">
163+
{this.state.manifest.commit.message}
164+
</span>
165+
</div>
166+
<div class="BuildPage__content__gitData__secondary">
167+
<span class="BuildPage__content__gitData__secondary__shortSha">
168+
{this.state.manifest.ref.slice(0, 7)}
169+
</span>
170+
&nbsp;on&nbsp;
171+
<span class="BuildPage__content__gitData__secondary__modified">
172+
{prettyDate(this.state.manifest.modified)}
173+
</span>
174+
</div>
175+
</div>
176+
) : (
177+
''
178+
)}
179+
</div>
180+
);
181+
}
182+
149183
render() {
150184
return (
151185
<div class="BuildPage">
@@ -164,6 +198,7 @@ export class BuildPage extends Page<BuildPageProps, BuildPageState> {
164198
</Link>
165199
</div>
166200
<div class="BuildPage__content">
201+
{this.state.loading ? '' : this.renderGitData()}
167202
{this.state.loading ? this.renderLoading() : this.renderPathsTable()}
168203
{this.state.loading ? '' : this.renderRedirectsTable()}
169204
</div>

src/webui/sass/pages/_buildpage.sass

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,22 @@
3131
background: #F7F8F8
3232

3333
.BuildPage__content__table__empty
34-
margin-top: $spacing-20
34+
margin-top: $spacing-20
35+
36+
.BuildPage__content__gitData
37+
align-items: center
38+
background: #F1F8FF
39+
border-radius: $spacing-10
40+
border: 1px solid #c8e1ff
41+
display: flex
42+
justify-content: space-between
43+
margin-bottom: $spacing-20
44+
padding: $spacing-15
45+
46+
.BuildPage__content__gitData__primary__author
47+
display: inline-block
48+
font-weight: 700
49+
margin-right: 5px
50+
51+
.BuildPage__content__gitData__secondary__shortSha
52+
font-family: Monaco, monospace

src/webui/sass/utils/_spacing.sass

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$spacing-10: 10px
2+
$spacing-15: 15px
13
$spacing-20: 20px
24
$spacing-40: 40px
35
$spacing-80: 80px

0 commit comments

Comments
 (0)