-
-
Notifications
You must be signed in to change notification settings - Fork 159
Metadata feature #252
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
Open
jhonny111s
wants to merge
2
commits into
cookpete:master
Choose a base branch
from
jhonny111s:metadata-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Metadata feature #252
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const merge = require('lodash/merge'); | ||
const { cmd, dotNotationToObject, readJson, niceDate } = require('./utils') | ||
|
||
const DIVIDER = '='; | ||
|
||
const fetchGitConfig = async () => { | ||
const config = (await cmd(`git config -l`)) | ||
|
||
return config | ||
.trim() | ||
.split('\n') | ||
.reduce((acum, item) => { | ||
const [key, value] = item.split(DIVIDER) | ||
return merge(acum, dotNotationToObject(key, value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why lodash and not |
||
}, {}) | ||
|
||
} | ||
|
||
const getMetadata = async (options) => { | ||
if (options.metadata !== true) { | ||
return {} | ||
} | ||
|
||
const PACKAGE_FILE = 'package.json' | ||
const config = await fetchGitConfig(); | ||
|
||
const pkg = await readJson(PACKAGE_FILE) | ||
|
||
const allowed = ['name', 'version', 'description', 'changos', 'keywords'] | ||
|
||
const meta = {}; | ||
allowed.forEach(element => { | ||
meta[element] = pkg[element]; | ||
}); | ||
|
||
return JSON.parse(JSON.stringify({ now: niceDate(new Date()), ...meta, ...config })) | ||
|
||
} | ||
|
||
module.exports = { | ||
getMetadata | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# {{metadata.name}} Changelog | ||
|
||
Description: {{metadata.description}} | ||
|
||
release date: {{metadata.now}} | ||
release owner name: {{metadata.user.name}} | ||
release owner email: {{metadata.user.email}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
now: "20 January 2021", | ||
version: "1.0.0", | ||
name: "my-repository", | ||
description: "description-repository", | ||
user: { name: "John Doe", email: "[email protected]" }, | ||
core: { | ||
editor: "nano", | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# my-repository Changelog | ||
|
||
Description: description-repository | ||
|
||
release date: 20 January 2021 | ||
release owner name: John Doe | ||
release owner email: [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { describe, it, beforeEach, afterEach } = require("mocha"); | ||
const { expect } = require("chai"); | ||
|
||
const { | ||
getMetadata, | ||
__Rewire__: mock, | ||
__ResetDependency__: unmock, | ||
} = require("../src/metadata"); | ||
|
||
describe("metadata", () => { | ||
beforeEach(() => { | ||
mock("niceDate", () => "20 January 2021"); | ||
mock("fetchGitConfig", () => { | ||
return { | ||
user: { name: "John Doe", email: "[email protected]" }, | ||
core: { | ||
editor: "nano", | ||
}, | ||
}; | ||
}); | ||
mock("readJson", () => { | ||
return { | ||
version: "1.0.0", | ||
name: "my-repository", | ||
description: "description-repository", | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
unmock("niceDate"); | ||
unmock("readJson"); | ||
unmock("fetchGitConfig"); | ||
}); | ||
|
||
it("should return data from git config and package json if metadata option is true", async () => { | ||
expect(await getMetadata({ metadata: true })).to.deep.equal({ | ||
now: "20 January 2021", | ||
version: "1.0.0", | ||
name: "my-repository", | ||
description: "description-repository", | ||
user: { name: "John Doe", email: "[email protected]" }, | ||
core: { | ||
editor: "nano", | ||
}, | ||
}); | ||
}); | ||
|
||
it("should return an empty object if metadata option is undefined or false", async () => { | ||
expect(await getMetadata({})).to.deep.equal({}); | ||
expect(await getMetadata({metadata:false})).to.deep.equal({}); | ||
expect(await getMetadata({metadata: 'true'})).to.deep.equal({}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
lodash
is a CVE magnet; please uselodash.merge
instead.