Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add commitedAt and ancestorCommittedAt #35

Merged
merged 2 commits into from Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions packages/cli/src/upload/upload.js
Expand Up @@ -72,7 +72,7 @@ function getCurrentHash() {
if (envVars.TRAVIS_PULL_REQUEST_SHA) return envVars.TRAVIS_PULL_REQUEST_SHA;
if (envVars.TRAVIS_COMMIT) return envVars.TRAVIS_COMMIT;

const result = childProcess.spawnSync('git', ['rev-list', '--no-merges', '-n', '1', 'HEAD'], {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this impact things or just readability preference?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw i find the new change to be more readable. one option per array entry is good

const result = childProcess.spawnSync('git', ['rev-list', '--no-merges', '-n1', 'HEAD'], {
encoding: 'utf8',
});
if (result.status !== 0) {
Expand All @@ -82,6 +82,21 @@ function getCurrentHash() {
return result.stdout.trim();
}

/**
* @param {string} hash
* @return {string}
*/
function getCommitTime(hash) {
const result = childProcess.spawnSync('git', ['log', '-n1', '--pretty="format:%cI"', hash], {
encoding: 'utf8',
});
if (result.status !== 0) {
throw new Error('Unable to retrieve committer timestamp from commit');
}

return result.stdout.trim();
}

/**
* @return {string}
*/
Expand Down Expand Up @@ -175,7 +190,7 @@ function getAncestorHashForBranch() {
});

if (result.status !== 0) {
throw new Error('Unable to determine current hash with `git merge-base HEAD master`');
throw new Error('Unable to determine ancestor hash with `git merge-base HEAD master`');
}

return result.stdout.trim();
Expand Down Expand Up @@ -312,18 +327,22 @@ async function runLHCITarget(options) {

const hash = getCurrentHash();
const branch = getCurrentBranch();
const ancestorHash =
branch === 'master' ? getAncestorHashForMaster() : getAncestorHashForBranch();

const build = await api.createBuild({
projectId: project.id,
lifecycle: 'unsealed',
hash,
branch,
ancestorHash,
commitMessage: getCommitMessage(hash),
author: getAuthor(hash),
avatarUrl: getAvatarUrl(hash),
ancestorHash: branch === 'master' ? getAncestorHashForMaster() : getAncestorHashForBranch(),
externalBuildUrl: getExternalBuildUrl(),
runAt: new Date().toISOString(),
committedAt: getCommitTime(hash),
ancestorCommittedAt: getCommitTime(ancestorHash),
});

print(`Saving CI project ${project.name} (${project.id})\n`);
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/api/storage/sql/build-model.js
Expand Up @@ -25,6 +25,8 @@ const attributes = {
ancestorHash: {type: Sequelize.STRING(40)},
externalBuildUrl: {type: Sequelize.STRING(256)},
runAt: {type: Sequelize.DATE()}, // should mostly be equal to createdAt but modifiable by the consumer
committedAt: {type: Sequelize.DATE()},
ancestorCommittedAt: {type: Sequelize.DATE()},
};

module.exports = {
Expand Down
@@ -0,0 +1,26 @@
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
*/
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('builds', 'committedAt', {type: Sequelize.DATE()});
await queryInterface.addColumn('builds', 'ancestorCommittedAt', {type: Sequelize.DATE()});
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
*/
down: async queryInterface => {
await queryInterface.removeColumn('builds', 'committedAt');
await queryInterface.removeColumn('builds', 'ancestorCommittedAt');
},
};
8 changes: 8 additions & 0 deletions packages/server/test/server-test-suite.js
Expand Up @@ -91,6 +91,8 @@ function runTests(state) {
commitMessage: 'feat: add some awesome features',
ancestorHash: '0ed0fdcfdce0acdd5eb2508498be50cc55c696ea',
runAt: new Date().toISOString(),
committedAt: new Date().toISOString(),
ancestorCommittedAt: new Date().toISOString(),
};

buildA = await client.createBuild(payload);
Expand All @@ -111,6 +113,8 @@ function runTests(state) {
commitMessage: 'feat: add some more awesome features',
ancestorHash: buildA.hash,
runAt: new Date().toISOString(),
committedAt: new Date().toISOString(),
ancestorCommittedAt: new Date().toISOString(),
};

buildB = await client.createBuild(payload);
Expand All @@ -131,6 +135,8 @@ function runTests(state) {
commitMessage: 'feat: a branch without an ancestor',
ancestorHash: '',
runAt: new Date().toISOString(),
committedAt: new Date().toISOString(),
ancestorCommittedAt: new Date().toISOString(),
};

buildC = await client.createBuild(payload);
Expand All @@ -151,6 +157,8 @@ function runTests(state) {
commitMessage: 'feat: initial commit',
ancestorHash: '',
runAt: new Date().toISOString(),
committedAt: new Date().toISOString(),
ancestorCommittedAt: new Date().toISOString(),
};

buildD = await client.createBuild(payload);
Expand Down
2 changes: 2 additions & 0 deletions types/server.d.ts
Expand Up @@ -36,6 +36,8 @@ declare global {
author?: string;
avatarUrl?: string;
ancestorHash?: string;
committedAt?: string;
ancestorCommittedAt?: string;
createdAt?: string;
updatedAt?: string;
}
Expand Down