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

Incorrect behavior of GHRepository.getReadme #150

Closed
vbauer opened this issue Jan 22, 2015 · 3 comments
Closed

Incorrect behavior of GHRepository.getReadme #150

vbauer opened this issue Jan 22, 2015 · 3 comments

Comments

@vbauer
Copy link

vbauer commented Jan 22, 2015

I've got the following error, trying to fetch README file from https://github.com/matshofman/Android-RSS-Reader-Library:

java.io.FileNotFoundException: https://api.github.com/repos/matshofman/Android-RSS-Reader-Library/contents/readme
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1834) ~[na:1.8.0_11]
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439) ~[na:1.8.0_11]
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) ~[na:1.8.0_11]
    at org.kohsuke.github.Requester.parse(Requester.java:383) ~[github-api-1.59.jar:na]
    at org.kohsuke.github.Requester._to(Requester.java:185) ~[github-api-1.59.jar:na]
    at org.kohsuke.github.Requester.to(Requester.java:160) ~[github-api-1.59.jar:na]
    at org.kohsuke.github.GHRepository.getFileContent(GHRepository.java:917) ~[github-api-1.59.jar:na]
    at org.kohsuke.github.GHRepository.getFileContent(GHRepository.java:907) ~[github-api-1.59.jar:na]
    at org.kohsuke.github.GHRepository.getReadme(GHRepository.java:939) ~[github-api-1.59.jar:na]
    at com.android.arsenal.service.impl.ConverterServiceImpl.convertRepository(ConverterServiceImpl.java:62) ~[classes/:na]
    at com.android.arsenal.service.impl.ProcessorServiceImpl.process(ProcessorServiceImpl.java:135) ~[classes/:na]
    at com.android.arsenal.service.impl.ProcessorServiceImpl.access$100(ProcessorServiceImpl.java:33) ~[classes/:na]
    at com.android.arsenal.service.impl.ProcessorServiceImpl$2.run(ProcessorServiceImpl.java:99) ~[classes/:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_11]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_11]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_11]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_11]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_11]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_11]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_11]

The reason of this problem that readme-file was called "README.markdown" and github-api doesn't use specific Github API to fetch info about README. It just tries to download "readme" file from repository.

Additional information could be found here: https://developer.github.com/v3/repos/contents/

API call should be like this: GET /repos/:owner/:repo/readme

UPD: It will be also useful to add method getReadmHtml and use 'application/vnd.github.VERSION.html' to retrieve HTML document.

@vbauer
Copy link
Author

vbauer commented Jan 24, 2015

My dirty workaround:

    public String getReadme(final GHRepository repository) throws Exception {
        final GitHub gitHub = getRoot(repository);
        final String login = getOwnerName(repository);
        final String name = repository.getName();

        try {
            final String authorization = ReflectionUtils.get(gitHub, "encodedAuthorization");
            final String apiUrl = "https://api.github.com" + repositoryApiCall(login, name) + "/readme";

            final int timeout = configuration.getTimeout();
            final TimeoutHttpConnector connector = new TimeoutHttpConnector(timeout);
            final HttpURLConnection connection = connector.connect(new URL((apiUrl)));
            try {
                connection.setRequestProperty(HttpHeaders.ACCEPT, "application/vnd.github.VERSION.html");
                connection.setRequestProperty(HttpHeaders.AUTHORIZATION, authorization);

                connection.connect();
                return IOUtils.toString(connection.getInputStream());
            } finally {
                try {
                    connection.disconnect();
                } catch (final Throwable ignored) {
                    // Ignored.
                }
            }
        } catch (final Throwable ex) {
            logger.error("Can't fetch README file from repository {}/{}: {}", login, name, ex.getMessage());
            return null;
        }
    }

@kohsuke
Copy link
Collaborator

kohsuke commented Feb 15, 2015

Duplicate of issue #99.

@kohsuke kohsuke closed this as completed Feb 15, 2015
@vbauer
Copy link
Author

vbauer commented Feb 15, 2015

I'm not sure that it's completely duplicated issue. My variant retrieves HTML document instead of Markdown ("Accept: application/vnd.github.VERSION.html")

I think it will be better to add additional method to retrieve HTML content.

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

No branches or pull requests

2 participants