Claus Ibsen created CAMEL-25983:
-----------------------------------

             Summary: camel-github2 - getCommitFile passes the commit sha to 
getBlob, never uses the file path, and decodes the content with the wrong 
base64 decoder
                 Key: CAMEL-25983
                 URL: https://issues.apache.org/jira/browse/CAMEL-25983
             Project: Camel
          Issue Type: Bug
          Components: camel-github
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


The getCommitFile producer of camel-github2 cannot give the content of a file 
({{GetCommitFileProducer}}, main e6885df7894d):
* it passes the same sha to {{getRepository().getCommit(sha)}} (line 53) and to 
{{getRepository().getBlob(sha)}} (lines 61 and 63). A git object cannot be both 
a commit and a blob, so one of the two calls fails. Both branches of the {{if}} 
at line 59 call {{getBlob(sha)}}, the commit is not used, and the path of the 
file is never used;
* when the {{CamelGitHubCommitSha}} header is not set, the body is taken as the 
sha (line 46), and at line 58 the body is read again as the path of the file;
* the content of the blob is decoded with {{Base64.getDecoder()}} (line 70), 
which rejects the line-wrapped base64 GitHub returns; {{GHBlob.read()}} of 
github-api uses the MIME decoder;
* the docs (github2-component.adoc) say getCommitFile takes no body and a 
{{CamelGitHubFilePath}} header, which does not exist in the code, and the 
javadoc of the class says the body is the path of the file.

The producer has no test (GitHub2ComponentTest only checks the names of the 
enum).

Proposed change: take the sha of the commit from the {{CamelGitHubCommitSha}} 
header and the path of the file from a {{CamelGitHubFilePath}} header (or the 
body), check that the sha is a commit id (40 hex characters), read the file 
from the tree of that commit, decode the content with the MIME decoder, 
document the headers, and add a test with a mocked GitHub client.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to