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

v0.5.0 #102

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

v0.5.0 #102

wants to merge 4 commits into from

Conversation

tuunit
Copy link
Collaborator

@tuunit tuunit commented Jun 8, 2023

tuunit and others added 3 commits June 6, 2023 09:45
- add direct urls for comments and replace custom url handling with html_url property provided by github api
- remove redundant else branches
- separate into if blocks for better readability
- remove unnecessary constant for github base url

Co-authored-by: James George <[email protected]>
@tuunit tuunit requested a review from jamesgeorge007 June 8, 2023 21:12
Copy link
Owner

@jamesgeorge007 jamesgeorge007 left a comment

Choose a reason for hiding this comment

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

There're a few edge cases to be considered.

  • Exiting early if there are no changes to be made.
  • If there're empty lines after the <!--START_SECTION:activity--> comment. This is handled if the <!--END_SECTION:activity--> comment is present. If it's not the case and if the line after the <!--START_SECTION:activity--> comment is empty, let's show a message conveying the <!--END_SECTION:activity--> comment was not found, and it will be inserted towards the end. Also, empty lines were found after the <!--START_SECTION:activity--> comment and will be replaced by the activity events.

const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n");
const newContent = content
.map((line, idx) => `${idx + 1}. ${line}`)
.join("\n");
if (oldContent.trim() === newContent.trim())
tools.exit.success("No changes detected");
startIdx++;
// Recent GitHub Activity content between the comments
const readmeActivitySection = readmeContent.slice(startIdx, endIdx);
if (!readmeActivitySection.length) {
content.some((line, idx) => {
// User doesn't have 5 public events
if (!line) {
return true;
}
readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`);
});
tools.log.success(`Wrote to ${TARGET_FILE}`);
} else {
// It is likely that a newline is inserted after the <!--START_SECTION:activity--> comment (code formatter)
let count = 0;
readmeActivitySection.some((line, idx) => {
// User doesn't have 5 public events
if (!content[count]) {
return true;
}
if (line !== "") {
readmeContent[startIdx + idx] = `${count + 1}. ${content[count]}`;
count++;
}
});
tools.log.success(`Updated ${TARGET_FILE} with the recent activity`);
}

const resp = await tools.github.activity.listPublicEventsForUser({
username: GH_USERNAME,
per_page: 100,
page: page,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
page: page,
page,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'm personally not a fan of the shortened version in this instance as all the other parameters are explicitly named or set with a fixed value. it looks kind of strange to me when there is a line missing the key value pair. but if you have a strong preference for it i can change it.

Copy link
Owner

Choose a reason for hiding this comment

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

I find the object shorthand syntax handy and always prefer it. I see the point here not to mix it up and be explicit. If you ask me, I'd always go for the syntax sugar. If we can use the ES6 semantics, then why not leverage it? Feel free to take the call here.

index.js Outdated Show resolved Hide resolved
}
// Append new content
events.forEach((line, idx) =>
readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`)
readmeContent.splice(startIdx + idx, 1, `${idx + 1}. ${line}`)

There can be an edge case where the <!--END_SECTION:activity--> comment got removed, and the further runs will append entries towards the end rather than replacing them.

Copy link
Owner

Choose a reason for hiding this comment

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

On second thought, how about replacing the entry altogether instead of the splice approach?

Suggested change
readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`)
readmeContent[startIdx + idx] = `${idx + 1}. ${line}`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think you might have misunderstood how the logic works.

If the end section comment has been found all lines between Start and including the end section comment will be removed:
https://github.com/jamesgeorge007/github-activity-readme/blob/rc/0.5.0/index.js#L202-L205

The forEach in line in line 215 - 217 uses the splice method (starting after the start section comment) to insert each single message after each other. We cannot use the array notation here as that might cause an array out of bounds exception or overwrite any following other lines.

After each message was inserted using splice we add back the end section comment:

https://github.com/jamesgeorge007/github-activity-readme/blob/rc/0.5.0/index.js#L220-L225

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But you are right, if the end comment got removed by the user by accident and the old messages do still exist. We would append those messages with the new ones and put the new end comment in between. That would cause the issue that we would keep the old message forever. Unfortunately, I don't see any easy solution to deal with that kind of user error. How would we identify what is part of our list and what was added by the user on purpose? Do you have any ideas?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, let's not handle the case if the <!--END_SECTION:activity--> comment got removed later on; was wondering if it would be helpful to log a message in such a case.

If there're empty lines after the comment. This is handled if the comment is present. If it's not the case and if the line after the comment is empty, let's show a message conveying the comment was not found, and it will be inserted towards the end. Also, empty lines were found after the comment and will be replaced by the activity events.

index.js Outdated Show resolved Hide resolved
@jamesgeorge007 jamesgeorge007 changed the title build: rc/0.5.0 v0.5.0 Jun 29, 2023
@jamesgeorge007
Copy link
Owner

jamesgeorge007 commented Jun 29, 2023

@tuunit, for features/enhancements, let's ensure it is discussed before going ahead with the implementation. This would give us the time to hear from the community as well. Also, it'd be easier to review PRs individually :)

Since this involves a major refactor, shall we make a patch release to get #100 out?

@tuunit
Copy link
Collaborator Author

tuunit commented Jun 29, 2023

@jamesgeorge007 no problem I can just cherry pick the commit for the fix and create into another branch and create branch. I'll check your other comments later :)

@tuunit
Copy link
Collaborator Author

tuunit commented Jul 3, 2023

There're a few edge cases to be considered.

  1. Exiting early if there are no changes to be made.
  2. If there're empty lines after the <!--START_SECTION:activity--> comment. This is handled if the <!--END_SECTION:activity--> comment is present. If it's not the case and if the line after the <!--START_SECTION:activity--> comment is empty, let's show a message conveying the <!--END_SECTION:activity--> comment was not found, and it will be inserted towards the end. Also, empty lines were found after the <!--START_SECTION:activity--> comment and will be replaced by the activity events.

Regarding the edge cases:

  1. The new implementation always replaces everything between the start and end section comment and tries to commit and push it. In my opinion, we should not try to do any kind of "change detection". Git is the sophisticated change detection tool of choice and therefore should deal with this. No new commit or push will be happening if there wasn't any change. Additionally, this eliminates any logic necessary to deal with changes to the MAX_LINES and other parameters as we will always have a clean slate by removing all the previous messages.
  2. As for empty lines between the start and end section comment, this will be dealt with by the new logic as well as they will always be deleted. For empty lines after the start comment without an end comment. They might be intentionally by the user and therefore will be kept with the new implementation.

@tuunit
Copy link
Collaborator Author

tuunit commented Jul 3, 2023

@jamesgeorge007 I hope my explanations help to understand the new logic. I know it is a "major" change but I hope it leads to more stability 😊

@jamesgeorge007
Copy link
Owner

  1. The new implementation always replaces everything between the start and end section comment and tries to commit and push it. In my opinion, we should not try to do any kind of "change detection". Git is the sophisticated change detection tool of choice and therefore should deal with this. No new commit or push will be happening if there wasn't any change. Additionally, this eliminates any logic necessary to deal with changes to the MAX_LINES and other parameters as we will always have a clean slate by removing all the previous messages.

I concur. But, we used to exit early and log an appropriate message previously. Isn't it better to keep the behavior? We could even leverage Git to check for changes made during the workflow run instead of comparing the contents manually.

  1. As for empty lines between the start and end section comment, this will be dealt with by the new logic as well as they will always be deleted. For empty lines after the start comment without an end comment. They might be intentionally by the user and therefore will be kept with the new implementation.

#102 (comment)

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

Successfully merging this pull request may close these issues.

2 participants