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

fix: ensure updates to files maintain original sha #43

Merged
merged 3 commits into from
Jan 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ContentFiles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const AllContributorBotError = require('../utils/errors')
function modifyFiles({ contentFilesByPath, fileContentModifierFunction }) {
const newFilesByPath = {}
Object.entries(contentFilesByPath).forEach(
([filePath, { content, sha }]) => {
([filePath, { content, sha, originalSha }]) => {
const newFileContents = fileContentModifierFunction(content)
newFilesByPath[filePath] = {
content: newFileContents,
originalSha: sha,
originalSha: sha || originalSha,
}
},
)
Expand Down
27 changes: 27 additions & 0 deletions test/ContentFiles/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,30 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!"
`;

exports[`ContentFiles Init content 2`] = `
"# TestContentFIles
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)

A test for content files generation

### Content
1. Stuff here
2. Yeah boy

## LICENSE

[MIT](LICENSE)

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src=\\"https://avatars2.githubusercontent.com/u/3534236?v=4\\" width=\\"100px;\\" alt=\\"Jake Bolam\\"/><br /><sub><b>Jake Bolam</b></sub>](https://jakebolam.com)<br />[💻](#code-jakebolam \\"Code\\") [🤔](#ideas-jakebolam \\"Ideas, Planning, & Feedback\\") [🚇](#infra-jakebolam \\"Infrastructure (Hosting, Build-Tools, etc)\\") [⚠️](#test-jakebolam \\"Tests\\") | [<img src=\\"https://avatars2.githubusercontent.com/u/7265547?v=4\\" width=\\"100px;\\" alt=\\"tbenning\\"/><br /><sub><b>tbenning</b></sub>](https://github.com/tbenning)<br />[🎨](#design-tbenning \\"Design\\") |
| :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!"
`;
37 changes: 36 additions & 1 deletion test/ContentFiles/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ describe('ContentFiles', () => {
const contentFiles = new ContentFiles({
repository: mockRepository,
})
const mockSha = 'mock sha right here yo'
contentFiles.contentFilesByPath = {
'README.md': {
content: mockTestFileContentNoTable,
sha: mockSha,
},
}

Expand All @@ -73,6 +75,39 @@ describe('ContentFiles', () => {
}
contentFiles.init(mockOptionsConfig)

expect(contentFiles.get()['README.md'].content).toMatchSnapshot()
const readme = contentFiles.get()['README.md']
expect(readme.content).toMatchSnapshot()
expect(readme.originalSha).toEqual(mockSha)

const mockOptionsConfig2 = {
get: function() {
return {
contributorsPerLine: 7,
contributors: [
{
login: 'jakebolam',
name: 'Jake Bolam',
avatar_url:
'https://avatars2.githubusercontent.com/u/3534236?v=4',
profile: 'https://jakebolam.com',
contributions: ['code', 'ideas', 'infra', 'test'],
},
{
login: 'tbenning',
name: 'tbenning',
avatar_url:
'https://avatars2.githubusercontent.com/u/7265547?v=4',
profile: 'https://github.com/tbenning',
contributions: ['design'],
},
],
}
},
}
contentFiles.generate(mockOptionsConfig2)

const readme2 = contentFiles.get()['README.md']
expect(readme2.content).toMatchSnapshot()
expect(readme2.originalSha).toEqual(mockSha)
})
})
3 changes: 2 additions & 1 deletion test/__snapshots__/index-e2e.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ exports[`All Contributors app - End to end Happy path, add correct new contribut
Object {
"branch": "all-contributors/add-jakebolam",
"content": "IyBBbGxDb250cmlidXRvcnNCb3QKWyFbQWxsIENvbnRyaWJ1dG9yc10oaHR0cHM6Ly9pbWcuc2hpZWxkcy5pby9iYWRnZS9hbGxfY29udHJpYnV0b3JzLTEtb3JhbmdlLnN2Zz9zdHlsZT1mbGF0LXNxdWFyZSldKCNjb250cmlidXRvcnMpCkEgYm90IGZvciBhdXRvbWF0aWNhbGx5IGFkZGluZyBhbGwtY29udHJpYnV0b3JzLiDwn6SWCgpbIVtCdWlsZF0oaHR0cHM6Ly9pbWcuc2hpZWxkcy5pby9jaXJjbGVjaS9wcm9qZWN0L2dpdGh1Yi9hbGwtY29udHJpYnV0b3JzL2FsbC1jb250cmlidXRvcnMtYm90L21hc3Rlci5zdmcpXShodHRwczovL2NpcmNsZWNpLmNvbS9naC9hbGwtY29udHJpYnV0b3JzL2FsbC1jb250cmlidXRvcnMtYm90KQpbIVtDb3ZlcmFnZV0oaHR0cHM6Ly9pbWcuc2hpZWxkcy5pby9jb2RlY292L2MvZ2l0aHViL2FsbC1jb250cmlidXRvcnMvYWxsLWNvbnRyaWJ1dG9ycy1ib3Quc3ZnKV0oaHR0cHM6Ly9jb2RlY292LmlvL2dpdGh1Yi9hbGwtY29udHJpYnV0b3JzL2FsbC1jb250cmlidXRvcnMtYm90KQpbIVtBbGwgQ29udHJpYnV0b3JzXShodHRwczovL2ltZy5zaGllbGRzLmlvL2JhZGdlL2FsbF9jb250cmlidXRvcnMtMS1vcmFuZ2Uuc3ZnKV0oI2NvbnRyaWJ1dG9ycykKWyFbQ2hhdCBvbiBTbGFja10oaHR0cHM6Ly9pbWcuc2hpZWxkcy5pby9iYWRnZS9zbGFjay1qb2luLWZmNjliNC5zdmcpXShodHRwczovL2pvaW4uc2xhY2suY29tL3QvYWxsLWNvbnRy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E9SUy1MSVNUOkVORCAtLT4KClRoaXMgcHJvamVjdCBmb2xsb3dzIHRoZSBbYWxsLWNvbnRyaWJ1dG9yc10oaHR0cHM6Ly9naXRodWIuY29tL2FsbC1jb250cmlidXRvcnMvYWxsLWNvbnRyaWJ1dG9ycykgc3BlY2lmaWNhdGlvbi4gQ29udHJpYnV0aW9ucyBvZiBhbnkga2luZCB3ZWxjb21lCgojIyBMSUNFTlNFCgpbTUlUXShMSUNFTlNFKQo=",
"message": "docs: create README.md",
"message": "docs: update README.md",
"sha": "bfce087f5fbed22257de1ee5056b20de63da0a13",
}
`;

Expand Down