Skip to content

Commit

Permalink
refactor(types): use typings provided by file-util-git-history
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy committed Jun 27, 2021
1 parent 6a3bf01 commit 7f0b785
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@actions/core": "^1.4.0",
"@octokit/core": "^3.5.1",
"file-util-git-history": "^3.0.1",
"file-util-git-history": "^3.1.0",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"nodegit": "^0.27.0",
Expand Down
18 changes: 9 additions & 9 deletions report/src/trends/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ async function generateTrends(gitPath, latestReport, maxDaysHistory = 30) {

// get history for the report file
core.info(`Open GIT history for report.json`);
/** @type {GitHistory} */
const history = await gitHistory(`${gitPath}/report.json`);

// ensure git history is sorted from latest to oldest commit
history.sort((a, b) => b.commit.date() - a.commit.date());
history.sort((a, b) => b.commit.date().valueOf() - a.commit.date().valueOf());

// will only extract N days of history
const startDate = new Date(
new Date().getTime() - maxDaysHistory * 24 * 60 * 60 * 1000
);

/** @type {import("nodegit").Revwalk.HistoryEntry[]} */
const reduceInit = [];
// compile summary contents from reports
const commits = await Promise.all(
history
// include only relevant commits (in the date range)
.reduce(
/** @param {GitHistoryEntry[]} filteredCommits*/ (
(
filteredCommits,
entry,
i,
all
i
) => {
const isAfter = entry.commit.date() >= startDate;
const isFirstBefore = !isAfter && i === filteredCommits.length;
// include relvant commits
// include relevant commits
if (isAfter || isFirstBefore) {
filteredCommits.push(entry);
}
return filteredCommits;
},
[]
reduceInit
)
// extract summary content for each commit
.map(async ({ /** @type {Commit} */ commit }) => {
.map(async ({ commit }) => {
commit.repo = repo; // for some reason this is not populated by default and prevents `getEntry`
core.info(`Get GIT entry for ${commit.sha()}`);
const treeEntry = await commit.getEntry("report.json");
Expand All @@ -65,7 +65,7 @@ async function generateTrends(gitPath, latestReport, maxDaysHistory = 30) {
})
);

/** @type Trends */
/** @type {Trends} */
const urlsHistory = {};

// add the latest report first as a commit
Expand Down
11 changes: 6 additions & 5 deletions report/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.37.tgz"
integrity sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==

"@types/nodegit@^0.27.2":
"@types/nodegit@^0.27.0", "@types/nodegit@^0.27.2":
version "0.27.2"
resolved "https://registry.yarnpkg.com/@types/nodegit/-/nodegit-0.27.2.tgz#f7db4728786e050751b210d0489a9ec2248030c5"
integrity sha512-8UCRm0BOXNTq+KRHq1AC4hZ7SrVuPQYfTsBApRYXgRNNjAicn2CYyMccty5SPoSUx2JfmVD6j+F4uX4XhOQwMw==
Expand Down Expand Up @@ -2085,11 +2085,12 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

file-util-git-history@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/file-util-git-history/-/file-util-git-history-3.0.1.tgz#110d2e507592e276a323f3bf32ecad95cff6d42d"
integrity sha512-aiiRNQEtqEyq9oDLSfd4Z/pBeGR3Z89wGL9nvTxQq584ww08LZN43CmvfJZPhH82LQU6nqRUsmI2HdwLW1jEnA==
file-util-git-history@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/file-util-git-history/-/file-util-git-history-3.1.0.tgz#ebaea1d132a7ab67e4f993f3ef3c51c8c57d4aa4"
integrity sha512-6HqWb7gkVpdbrhzjL2kSsQ6kXhY3Jcqow4rhY+SxyMj2lhnDHxlwEquHjOtWEtoueXaAX5rNBnOmwVKydJ2/sA==
dependencies:
"@types/nodegit" "^0.27.0"
nodegit "^0.27.0"

fill-range@^4.0.0:
Expand Down
16 changes: 0 additions & 16 deletions types/trends.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
declare module "file-util-git-history";

// todo: use nodegit declarations
type Commit = {
date: function
getEntry: function
sha: function
repo: any
}

type GitHistoryEntry = {
commit: Commit;
};

type GitHistory = GitHistoryEntry[];

type UrlMetricsHistoryValue = { date: string; value: string | number };
type UrlMetricsHistoryValues = Record<string, UrlMetricsHistoryValue[]>;

Expand Down

0 comments on commit 7f0b785

Please sign in to comment.