-
-
Notifications
You must be signed in to change notification settings - Fork 22
WIP: Scrape README from GitHub if the source is provided #292
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package util | ||
|
|
||
| import java.io.FileNotFoundException | ||
|
|
||
| import scala.io.Source | ||
|
|
||
| object GitHubUtil { | ||
|
|
||
| private val identifier = "A-Za-z0-9-_" | ||
| private val gitHubUrlPattern = s"""http(s)?://github.com/[$identifier]+/[$identifier]+(/)?""".r.pattern | ||
| private val readmeUrl = "https://raw.githubusercontent.com/%s/%s/master/README.md" | ||
|
||
|
|
||
| def isGitHubUrl(url: String): Boolean = gitHubUrlPattern.matcher(url).matches() | ||
|
|
||
| def getReadme(user: String, project: String): Option[String] = { | ||
| try { | ||
| val readme = Source.fromURL(readmeUrl.format(user, project)).mkString | ||
| Some(readme) | ||
| } catch { | ||
| case _: FileNotFoundException => None | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
This should only do it if one is not manually provided, yes? If that is not the behaviour with this PR, it should be.
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.
I'm not quite sure what you're saying. This scrapes the README if a source URL is provided, and if it is from GitHub.
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.
I'm asking if this will overwrite an existing manually-created README.
Uh oh!
There was an error while loading. Please reload this page.
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.
When a Project is created, it creates a Home Page that has
Page.HomeMessagein it. Lines 448 - 451 retrieve the Page from database, passing thepagevariable as a default. This changes the default to the README it scraped from GitHub. It's basically replacing the text fromPage.HomeMessagewith the README. So no, it will not replace the Home Page after it has been edited.