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 last contributor to each document #980

Merged
merged 17 commits into from Oct 18, 2018

Conversation

fiennyangeln
Copy link
Contributor

Motivation

Create Contributor List for each documents (#858)

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Run yarn build on the website -- it will update the author list in the metadata

Related PRs

None

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Sep 25, 2018
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Sep 25, 2018

Deploy preview for docusaurus-preview ready!

Built with commit 821331e

https://deploy-preview-980--docusaurus-preview.netlify.com

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

The PR preview for v2 is available on
https://deploy-preview-980--munseo-preview.netlify.com/

To be honest I don't agree with this feature on v2 as this would best be left as a plugin and not every user would want it. I personally don't want to see bloated contributor A xxxx% on the docs

@JoelMarcey
Copy link
Contributor

@endiliey - does the Netlify preview actually show the contributor list? I don't see it.

This was a v1 feature request that would have been toggled by a siteConfig option. Can we just add this as a v1 update then instead?

@endiliey
Copy link
Contributor

endiliey commented Sep 25, 2018

@JoelMarcey

It's at the bottom, hahaha.
image

I do agree if it's on v1. But I think for v2 our paradigm is that we don't want a lot of siteConfig and try to keep things as simple as possible especially on UI related things like this.

In addition, I think it's not a good idea to add the field into the docs metadata itself.

In the UI itself, we are exposed metadata.source which is an absolute path to this current docs file, we can just git blame that. So it's more efficient :)

@fiennyangeln
Copy link
Contributor Author

fiennyangeln commented Sep 29, 2018

@JoelMarcey @endiliey I finished doing git blame on the filePath, but i just realized it may not show the correct contributors name, instead, it show the name of whoever cut the version and the changes after it. It is because when we copy a file, we dont use git command so the file history kinda disappear.

My proposed solution would be:

  1. Get the contributor name when we cut a version (put it in metadata or some other places)
  2. Create a one time script to generate the author of each docs to be put in the metadata: for every file in the versioned_docs -> get the time of the first commit which would be the time when the version is made, go to the /docs/[filename], get the snapshot of the file at that moment, and get the contributors at that time -> save to metadata when we made the file.

But, we still need to think of edge case like how if the readme inside versioned_docs get changed, how shall we combine the result from /docs and /versioned_docs?

@endiliey
Copy link
Contributor

endiliey commented Sep 30, 2018

That is correct. Do note we have version fallback on v1 & that make things even more complicated.

To be honest I don't agree with this feature on v2 as this would best be left as a plugin and not every user would want it. I personally don't want to see bloated contributor A xxxx% on the docs

Maybe I should say its the same for v1. But ofc it could be a good addition to have.

WDYT @JoelMarcey @yangshun

@JoelMarcey
Copy link
Contributor

I think this feature was always intended for v1.

I have to scope change thoughts two this, if we believe contributors are becoming too difficult or cumbersome:

  1. One thought here is that we could change the scope of this to be where the last content commit to the docs is shown with a link to the commit.
  2. We have a link to the full history of changes for the doc. Basically have a link that brings you directly to something like this: https://github.com/facebook/Docusaurus/commits/master/docs/api-site-config.md

@fiennyangeln
Copy link
Contributor Author

Now that the last updated time is merged, I will start working back on this. Do we want the last updated by field instead? @yangshun @JoelMarcey

- s/getGitlastupdated/getGitLastUpdatedTime
- refactor part in getGitLastUpdated[Time|By] that overlaps
- remove getAuthorInformation
Copy link
Contributor

@JoelMarcey JoelMarcey left a comment

Choose a reason for hiding this comment

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

I ❤️ the way this looks on the preview.

Is there anyway to have a link to the commit represented by the last update time and last committer?

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Code looks good, just have some suggestions regarding formatting!

<div className="docLastUpdateTimestamp">
{(updateTime || updateAuthor) && (
<div className="docLastUpdate">
{updateTime && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a combined format:

  • Only enableUpdateTime: "Last updated on 2018-10-15 01:23"
  • Only enableUpdateBy: "Last updated by @fiennyangeln"
  • Both enableUpdateTime and enableUpdateBy: "Last updated on 2018-10-15 01:23 by @fiennyangeln"

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's nice 😍 ! I will implement this.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Gave a more thorough review. Please let me know if you have questions!

}

// Wrap in try/catch in case the shell commands fail (e.g. project doesn't use Git, etc).
try {
const format = GIT_LAST_UPDATED_TYPE.TIME === type ? '%ct' : 'author=%an';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the author here?

Let's do away with this format variable. Instead, we could do

git log --follow --summary --format="%ct, %an" <file>

which would generate something like:

1539553317, Yangshun Tay

1539457591, Yangshun Tay

1539185600, Yangshun Tay

1538339532, Fienny Angelina

1537426859, Marvin Heilemann

1537330146, Yangshun Tay

1537203487, Yangshun Tay

 copy package.json => v1/package.json (81%)
1537169695, Yangshun Tay

1537157761, Yangshun Tay

1537157671, Endilie Y

1537157183, endiliey

and then parse each line for the timestamp and author using a regex that extracts the timestamp and the author. Exampe regex here - https://regex101.com/r/O0HQrc/1

This method will just return both the relevant timestamp and author as an object { timestamp: 12345, author: 'Fienny' }, and it's up to the callsite to use whichever field they need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially put the author to differentiate author vs commit summary since both are just plain string 😁 Wdyt about making it stronger like ^(\d{10}), (.+)$ ? It can last until 2038 based on Google


const records = getGitLastUpdated(filepath, GIT_LAST_UPDATED_TYPE.TIME);

const timeSpan = records.find((item, index, arr) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This finding logic can be shifted into the getGitLastUpdated method.

And getGitLastUpdatedTime will in the end just become:

function getGitLastUpdatedTime(filepath) {
  const commit = getGitLastUpdated(filepath);
  if (!commit) {
    return null;
  }

  const date = new Date(parseInt(commit.timestamp, 10) * 1000);
  return date.toLocaleString();
}

@yangshun
Copy link
Contributor

Is there anyway to have a link to the commit represented by the last update time and last committer?

It's possible but not sure how much value it provides. Going directly to the list of commits for the file would be more valuable. We could do this in a follow up PR though.

@JoelMarcey
Copy link
Contributor

It's possible but not sure how much value it provides. Going directly to the list of commits for the file would be more valuable.

I think we can debate which is more valuable, but I am ok with going to a list of commits (in fact, I may have suggested even that option before). I am quite certain though, having a link to somewhere makes more sense than having no link at all.

screenshot 2018-10-15 12 03 38

I would totally expect as a user to have a link to some commit or a list of commits for the file or something.

-Refactor the utils, combine lastupdatedtime and lastupdatedby
-Replace the test
@yangshun yangshun changed the title add contributor list to each document feat: add last contributor to each document Oct 18, 2018
@@ -135,6 +135,9 @@ Set this to `true` if you want to enable Facebook comments at the bottom of your
#### `fonts` [object]
Font-family CSS configuration for the site. If a font family is specified in `siteConfig.js` as `$myFont`, then adding a `myFont` key to an array in `fonts` will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so ordering of the fonts matter.

#### `enableUpdateBy` [boolean]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a wrong place to put this. Now it's in between the fonts config.

@@ -135,6 +135,9 @@ Set this to `true` if you want to enable Facebook comments at the bottom of your
#### `fonts` [object]
Font-family CSS configuration for the site. If a font family is specified in `siteConfig.js` as `$myFont`, then adding a `myFont` key to an array in `fonts` will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so ordering of the fonts matter.

#### `enableUpdateBy` [boolean]
An option to enable the docs showing last update time. Set to `true` to show a line at the bottom right corner of each doc page as `Last updated by <Author Name>`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy paste error... Should be about last author not last update time.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

There are some small nits which I have made on your behalf. Additionally, I changed the updated time format to show just the date as the timing is not that crucial. Thanks for making this happen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants