Giter Club home page Giter Club logo

Comments (12)

adpi2 avatar adpi2 commented on June 8, 2024

Thanks for the bug report.

from scaladex.

dongxuwang avatar dongxuwang commented on June 8, 2024

After looking through the code, looks that's not easy to figure this out.

from scaladex.

adpi2 avatar adpi2 commented on June 8, 2024

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.

mfirry avatar mfirry commented on June 8, 2024

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.

adpi2 avatar adpi2 commented on June 8, 2024

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.

mfirry avatar mfirry commented on June 8, 2024

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.

mfirry avatar mfirry commented on June 8, 2024

I'll try and summarize a possible solution.

As of now def fetchAndReplaceReadme(element: Element, ... does few things:

  1. It retrives the readme information
    val request = new Request(
      s"https://api.github.com/repos/$organization/$repository/readme", ...)
  1. Updates the markup for the given element (element.innerHTML = res)
  2. Checks all img and a elements and for them checks whether they have href or src attributes and then sets them to some specific values that can be github.com/$organization/$repository/raw/$branch or github.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.

adpi2 avatar adpi2 commented on June 8, 2024

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.

mfirry avatar mfirry commented on June 8, 2024

Cool. I'm just wondering if I've got an easy way to test that this works. Any hint?

from scaladex.

adpi2 avatar adpi2 commented on June 8, 2024

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.

mfirry avatar mfirry commented on June 8, 2024

Working on it have a look mfirry@d960fa3

still trying to understand if can i somehow handle unsuccessful API calls

from scaladex.

adpi2 avatar adpi2 commented on June 8, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.