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 modified dates in docs #2478

Closed

Conversation

philyoosays
Copy link
Collaborator

@philyoosays philyoosays commented Jan 9, 2024

Description

This PR adds a fetch to the Github REST API to collect the last modified date for commits to MASTG markdown files for display in the MASTG mkdocs site.

As a fallback in case the GITHUB_TOKEN was not able to be retrieved from the Github Actions pipeline, the original code to get last modified dates was preserved and called.

Issue

The issue being fixed has to do with the last modified dates being incorrect in the published mkdocs site. It seems that the Github Actions pipeline is copying the files and the original code that determines the last modified dates is using the local terminal git log method to determine last modified date. This is causing all the files to have the same last modified date (date of merge to master for any file) that does not match the actual last modified dates for the files in the repository.

The Fix

To be sure that we have an accurate commit history, this fix uses the Github REST API to fetch the commit history for each markdown file from the repository.

Note To Maintainers: Please make sure that the GITHUB_TOKEN has read access to content.


Thank you for submitting a Pull Request to the OWASP MASTG. Please make sure that:

  • Your contribution is written in the 2nd person (e.g. you)
  • Your contribution is written in an active present form for as much as possible.
  • You have made sure that the reference section is up to date (e.g. please add sources you have used, make sure that the references to MITRE/MASVS/etc. are up to date)
  • Your contribution has proper formatted markdown and/or code
  • Any references to website have been formatted as [TEXT](URL “NAME”)
  • You verified/tested the effectiveness of your contribution (e.g.: is the code really an effective remediation? Please verify it works!)

If your PR is related to an issue. Please end your PR test with the following line:
This PR closes #< insert number here >.

Copy link
Collaborator

@cpholguera cpholguera left a comment

Choose a reason for hiding this comment

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

Thanks @philyoosays! Here a couple of suggestions. Apart from that I'm just worried about the time that it takes to retrieve all data for all files (which can be hundreds). Let's discuss on Slack.

src/scripts/git_data.py Outdated Show resolved Hide resolved
src/scripts/git_data.py Outdated Show resolved Hide resolved
src/scripts/git_data.py Show resolved Hide resolved

if GITHUB_TOKEN is None:
print('Github token not found')
return get_last_commit_date_by_terminal_log(file_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can get rid of that function and return None or "N/A" here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/scripts/git_data.py Outdated Show resolved Hide resolved
src/scripts/git_data.py Outdated Show resolved Hide resolved
src/scripts/git_data.py Outdated Show resolved Hide resolved
@@ -21,7 +21,9 @@ jobs:

- run: ./src/scripts/structure_mastg.sh

- run: python3 src/scripts/transform_files.py
- env:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might work without this. The GITHUB_TOKEN is created automatically on each run and should be accessible to the script via env.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's try. We can always revert the commit that removes this declaration

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cpholguera
Copy link
Collaborator

Fixed with depth=0 in #2564

@cpholguera cpholguera closed this Feb 20, 2024
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