Comments (12)
Thanks for the bug report.
from scaladex.
After looking through the code, looks that's not easy to figure this out.
from scaladex.
I guess we need to use the GithubClient
to get the default branch and store that into GithubInfo
(which is saved in a SQL table). Then use that info to get the correct URL of images.
If you have time to look into that, it would be helpful.
from scaladex.
what if just before this (or in parallel) call to github api
val request = new Request(
s"https://api.github.com/repos/$organization/$repository/readme",
new RequestInit {
headers = headersWithCreds.toJSDictionary
}
)
One makes this other one https://api.github.com/repos/$organization/$repository/
with which you can get the default_branch
?
from scaladex.
One makes this other one https://api.github.com/repos/$organization/$repository/ with which you can get the default_branch?
Yes that should solve the issue! Feel free to open a PR.
from scaladex.
I'll give it a shot!
to be fair: it's not the solution... I see it as a workaround but it should a) serve the purpose b) have little impact on the structure of that part of the codebase.
from scaladex.
I'll try and summarize a possible solution.
As of now def fetchAndReplaceReadme(element: Element, ...
does few things:
- It retrives the readme information
val request = new Request(
s"https://api.github.com/repos/$organization/$repository/readme", ...)
- Updates the markup for the given
element
(element.innerHTML = res
) - Checks all
img
anda
elements and for them checks whether they havehref
orsrc
attributes and then sets them to some specific values that can begithub.com/$organization/$repository/raw/$branch
orgithub.com/$organization/$repository/blob/$branch
(and branch is master)
Now what I had in mind is to keep point 1 and 2 as they and separate the rest.
So the first part would look like:
// Simplified version
fetch(readmeRequest).toFuture
.flatMap { res =>
res.text().toFuture
}
.foreach(res => element.innerHTML = res)
The second one would make the "new" GitHub API request (repoRequest
), parse the JSON and retrieve the default_branch
. Only then It can go on with updating href
attributes for the anchors and the images.
So something along these lines:
// Simplified version
@js.native
trait Repo extends js.Object {
val default_branch: String = js.native
}
(...)
val repoRequest = new Request(
s"https://api.github.com/repos/$organization/$repository/", ...)
fetch(repoRequest).toFuture
.flatMap(res => res.text().toFuture)
.foreach { res =>
val resJson = js.JSON.parse(res)
val branch = resJson.asInstanceOf[Repo].default_branch
setImagesAndAnchors(branch, organization, repository)
}
(And obviously setImagesAndAnchors
does what it says it does)
How does this look like?
from scaladex.
How does this look like?
Looks good but the second part (or more precisely the setImagesAndAnchors
) should not happen before the first part finishes. So there should be some map
or flatMap
to synchronize them.
from scaladex.
Cool. I'm just wondering if I've got an easy way to test that this works. Any hint?
from scaladex.
Cool. I'm just wondering if I've got an easy way to test that this works. Any hint?
This is how you can run Scaladex locally: https://github.com/scalacenter/scaladex/blob/main/CONTRIBUTING.md#run-scaladex-locally. Then you should go to the scalacenter/bloop
project and see if the image appears.
from scaladex.
Working on it have a look mfirry@d960fa3
still trying to understand if can i somehow handle unsuccessful API calls
from scaladex.
@mfirry thanks for the update. It is looking good.
still trying to understand if can i somehow handle unsuccessful API calls
The API call should not fail and if it fails I would use master
as the default branch.
from scaladex.
Related Issues (20)
- [Bug] Project not being indexed HOT 11
- [Bug] 404 for all CSS HOT 2
- Cannot log in HOT 1
- Show Scala versions in descending order HOT 4
- Drop Scala 2.10 support HOT 1
- Scaladex is down HOT 1
- Scaladex is down HOT 1
- [Bug] The Site is down HOT 3
- [Bug] Incorrect Mill plugin in "Asset management and bundlers" page
- hbase-connector for scala 2.2.17 HOT 1
- [Bug] missing-maven-artifact job fails with DateTimeParseException
- [Bug] SchedulerService in contributing.md has been 404 HOT 1
- [Bug] JSON error message when project has no readme HOT 5
- [Bug] sbt-scalafix not found HOT 2
- Scala CLI deps for Scala.js libraries HOT 3
- Add an intermediate Artifacts page on a project HOT 8
- Suggestion to Add Pull Request Template HOT 3
- Add Dependents tab in project page
- [Bug] Setup Bug with the Windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scaladex.