jonnyzzz / TeamCity.GitHub

Integration of TeamCity and GitHub
216 stars 63 forks source link

404 error on updating status #12

Open tobico opened 11 years ago

tobico commented 11 years ago

Using version 0.4.48 I'm getting an error whenever the plugin tries to update github:

[2013-03-07 11:04:26,227] WARN - lty.github.ChangeStatusUpdater - Failed to update GitHub status for hash: 0e9a24313e6e34f6c373e7062d0eebaffb9037f0, buildId: 180, status: Success. Failed to complete request to GitHub. Status: HTTP/1.1 404 Not Found java.io.IOException: Failed to complete request to GitHub. Status: HTTP/1.1 404 Not Found at jetbrains.teamcilty.github.api.impl.GitHubApiImpl.setChangeStatus(GitHubApiImpl.java:105) at jetbrains.teamcilty.github.ChangeStatusUpdater$1$1.run(ChangeStatusUpdater.java:131) at jetbrains.buildServer.util.ExceptionUtil$1.run(ExceptionUtil.java:40) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:679)

As far as I can tell all of the settings are configured correctly.

jonnyzzz commented 11 years ago

What version of plugin was it? What branch spec have you specified? Please consider updating to the latest version of plugin. Have you added a newer commit to a pull request?

jonnyzzz commented 11 years ago

Please also check you do not have misprints in the repo name or owner name in the build feature settings

tomspilman commented 11 years ago

I'm getting the same error.

@jonnyzzz - Can you maybe fix the logging to include the URL that failed? It should point out pretty quickly what the error is.

jonnyzzz commented 11 years ago

There should be more details if debug logging is enabled. I'll check this out

scullyx13 commented 11 years ago

Hello!

We have this problem with version of plugin: 0.4.46, 0.4.50. We use github enterprise. Have you tested for compatibility with the api in enterprise version?

jonnyzzz commented 11 years ago

Could you please enable debug logs and check what errors from the plugin you see there. It should work with latest build. Unfortunately, I do not have an access to private repos now

scullyx13 commented 11 years ago

Could you please enable debug logs and check what errors from the plugin you see there. It should work with latest build.

Ok, we will try.

Unfortunately, I do not have an access to private repos now

We use https://enterprise.github.com/, not private repos.

worldspawn commented 11 years ago

Hey i'm having this drama with github enterprise too :(

+1 for a fix

I set the diagnostics to debug - all this was the output

[2013-03-20 17:32:50,440]  DEBUG - .github.api.impl.GitHubApiImpl - Failed to complete query to GitHub with:
  requestURL: https://git.mycompany.com.au/repos/raven/MyCompany.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac
  requestEntity: {"state":"success","target_url":"https://teamcity.mycompany.com.au/viewLog.html?buildId\u003d533\u0026buildTypeId\u003dbt15","description":"TeamCity Build Raven Helpers :: MyCompany Framework PreRelease finished: Tests passed: 8"}
  response: HTTP/1.1 404 Not Found
  responseEntity: {"error":"Not Found"} 
[2013-03-20 17:32:50,440]   WARN - lty.github.ChangeStatusUpdater - Failed to update GitHub status for hash: b383261dd86cc4711cf6c9ab2b261aafe7dd46ac, buildId: 533, status: Success. Failed to complete request to GitHub. Status: HTTP/1.1 404 Not Found 
java.io.IOException: Failed to complete request to GitHub. Status: HTTP/1.1 404 Not Found
    at jetbrains.teamcilty.github.api.impl.GitHubApiImpl.setChangeStatus(GitHubApiImpl.java:139)
    at jetbrains.teamcilty.github.ChangeStatusUpdater$1$1.run(ChangeStatusUpdater.java:101)
    at jetbrains.buildServer.util.ExceptionUtil$1.run(ExceptionUtil.java:40)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I've set the domain in the feature set to to just the root of the deployment. eg https://git.mypany.com.au

Tried with and without trailing slash.

worldspawn commented 11 years ago

So the url was https://git.mycompany.com.au/repos/raven/MyCompany.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac

Which gives me a 404 in my browser

worldspawn commented 11 years ago

Change the config to point to /api/v3 and now the logged url is: https://git.kiandra.com.au/api/v3/repos/raven/Kiandra.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac

I composed a manual post in fiddler and got the same 404.

POST https://git.mycompany.com.au/api/v3/repos/raven/mycompany.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac HTTP/1.1
User-Agent: Fiddler
Host: git.mycompany.com.au
Authorization: Basic <Base64>
Content-Length: 227

 {"state":"success","target_url":"https://teamcity.mycompany.com.au/viewLog.html?buildId\u003d535\u0026buildTypeId\u003dbt15","description":"TeamCity Build Raven Helpers :: Kiandra Framework PreRelease finished: Tests passed: 8"}
jonnyzzz commented 11 years ago

Do you use the version of GitHub.enterprise that supports statuses api?

Do you know what URL to update status works with your github instance.

Do you see error message only for this query? Was that a pull request where you see the issue reproducing? What is the commit hash in your repo?

Unfortunately, I do not have an access to GitHub.enterprise to test it. On Mar 20, 2013 7:55 AM, "Sam Critchley" notifications@github.com wrote:

Change the config to point to /api/v3 and now the logged url is:

https://git.kiandra.com.au/api/v3/repos/raven/Kiandra.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac

I composed a manual post in fiddler and got the same 404.

POST https://git.mycompany.com.au/api/v3/repos/raven/mycompany.Framework/statuses/b383261dd86cc4711cf6c9ab2b261aafe7dd46ac HTTP/1.1 User-Agent: Fiddler Host: git.mycompany.com.au Authorization: Basic Content-Length: 227

{"state":"success","target_url":"https://teamcity.kiandra.com.au/viewLog.html?buildId\u003d535\u0026buildTypeId\u003dbt15","description":"TeamCity Build Raven Helpers :: Kiandra Framework PreRelease finished: Tests passed: 8"}

— Reply to this email directly or view it on GitHubhttps://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15160916 .

worldspawn commented 11 years ago

Hey jonny,

You should include a note about the url needing /api/v3 appended to the host for enterprise. Otherwise should be fine.

It was all down to the user account being used to push the status changes. The user needs push (i think) permission to the repo in question. That is the repo being target for the pull request (not the source repo). Once I added my service user to the organisation (with push permission) it just worked... kind of obvious really :)

jonnyzzz commented 11 years ago

Thanks for update. Does that mean that TeamCity user should have permissions in all repos from what one creates pull request? Or only for the repo where pull request is created? On Mar 20, 2013 8:24 AM, "Sam Critchley" notifications@github.com wrote:

So it was all down to the user account being used to push the status changes. The user needs push (i think) permission to the repo in question. That is the repo being target for the pull request (not the source repo). Once I fixed that up it just worked... kind of obvious really :)

— Reply to this email directly or view it on GitHubhttps://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15161477 .

worldspawn commented 11 years ago

Its only needed for the destination repo, not the source.

worldspawn commented 11 years ago

I am noticing only the head build is published to the PR not the merge, from what I read in other issues I was lead to believe that was fixed... but that's another issue.

jonnyzzz commented 11 years ago

Yes. I search for head hash via api when build is started on merge. The thing is that merge hash is dynamic and thus GH does not show updated status elsewhere for it. On Mar 20, 2013 8:32 AM, "Sam Critchley" notifications@github.com wrote:

I am noticing only the head build is published to the PR not the merge, from what I read in other issues I was lead to believe that was fixed.

— Reply to this email directly or view it on GitHubhttps://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15161660 .

worldspawn commented 11 years ago

If it searches for the HEAD hash to set the status for (when doing a merge) build i should see the HEAD hash being submitted (should be 09cedb3913d97dc7f8d5299a7650b42fa176c8b4) but instead I see 03290adf4c591f7f2bbb302449a462248d5e7ea4. Indeed the last time in the log it used 09cedb3913d97dc7f8d5299a7650b42fa176c8b4 was for build 541 which is what I see the build success message.

Perhaps I am confused, are you saying it should work or it should not work?

jonnyzzz commented 11 years ago

It should.

I take the latest hash for pull request as head. It may prefer newer commit than actual merge's parent

The code is I parse branch name to find pull request ID, next I call GH api to get head commit hash for pull request On Mar 20, 2013 8:41 AM, "Sam Critchley" notifications@github.com wrote:

If it searches for the HEAD hash to set the status for (when doing a merge) build i should see the HEAD hash being submitted (should be 09cedb3https://github.com/jonnyzzz/TeamCity.GitHub/commit/09cedb3913d97dc7f8d5299a7650b42fa176c8b4) but instead I see 03290adhttps://github.com/jonnyzzz/TeamCity.GitHub/commit/03290adf4c591f7f2bbb302449a462248d5e7ea4. Indeed the last time in the log it used 09cedb3https://github.com/jonnyzzz/TeamCity.GitHub/commit/09cedb3913d97dc7f8d5299a7650b42fa176c8b4was for build 541 which is what I see the build success message.

Perhaps I am confused, are you saying it should work or it should not work?

— Reply to this email directly or view it on GitHubhttps://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15161886 .

tomspilman commented 11 years ago

The user needs push (i think) permission to the repo in question.

I explicitly didn't give the bot account push access for security purposes, but I just tried it and it seems to be working now.

Need to probably update the instructions when hooking up the github account that it needs push access.

jonnyzzz commented 11 years ago

I believe there should be dedicated permission for status update. At least via github OAuth

worldspawn commented 11 years ago

Sorry @jonnyzzz but I dont see that occurring, at least in my environment.

Target for this build was 19/merge, which logged this:

[2013-03-21 09:39:26,552] INFO - lty.github.ChangeStatusUpdater - Scheduling GitHub status update for hash: 03290adf4c591f7f2bbb302449a462248d5e7ea4, buildId: 545, status: Success [2013-03-21 09:39:26,552] INFO - tbrains.buildServer.ACTIVITIES - Finished 545 [2013-03-21 09:39:26,584] INFO - lty.github.ChangeStatusUpdater - Updated GitHub status for hash: 03290adf4c591f7f2bbb302449a462248d5e7ea4, buildId: 545, status: Success

These are the commits on the pull request.

Test prteamcity by sam critchley Pull Request 19 raven Kiandra Framework

As you can see the hash used is not on the list of PR commits.

jonnyzzz commented 11 years ago

Thanks for logs. Let's continue the hash resolution problem in Issue #13. I have just commented there

On Wednesday, March 20, 2013, Sam Critchley wrote:

Sorry @jonnyzzz https://github.com/jonnyzzz but I dont see that occurring, at least in my environment.

Target for this build was 19/merge, which logged this:

[2013-03-21 09:39:26,552] INFO - lty.github.ChangeStatusUpdater - Scheduling GitHub status update for hash: 03290adhttps://github.com/jonnyzzz/TeamCity.GitHub/commit/03290adf4c591f7f2bbb302449a462248d5e7ea4, buildId: 545, status: Success [2013-03-21 09:39:26,552] INFO - tbrains.buildServer.ACTIVITIES - Finished 545 [2013-03-21 09:39:26,584] INFO - lty.github.ChangeStatusUpdater - Updated GitHub status for hash: 03290adhttps://github.com/jonnyzzz/TeamCity.GitHub/commit/03290adf4c591f7f2bbb302449a462248d5e7ea4, buildId: 545, status: Success

These are the commits on the pull request.

[image: Test prteamcity by sam critchley Pull Request 19 raven Kiandra Framework]https://f.cloud.github.com/assets/819581/283462/70b1fd06-91af-11e2-9a15-7af47e17012a.png

— Reply to this email directly or view it on GitHubhttps://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15208538 .

Best regards, Eugene Petrenko

simonoff commented 11 years ago

So this bug is fixed or not? Because I got the same bug with last version.

worldspawn commented 11 years ago

Yeh it's fixed. Check you didn't do what I did and download the latest version built on the windows build agent. The build agent isn't relevant, just grab the highest version number. (0.4.50)

simonoff commented 11 years ago

I has this 0.4.50 version. But it not working.

worldspawn commented 11 years ago

So are you getting a 404? Most likely cause is your using an account that does not have push access to the repository.

simonoff commented 11 years ago

Yes... Sorry but I not found info about this restriction in docs. Can you provide me the link on this restriction?

worldspawn commented 11 years ago

Well I guess I can't. Because it wasn't documented. Read from here: https://github.com/jonnyzzz/TeamCity.GitHub/issues/12#issuecomment-15161477

qbantek commented 11 years ago

From http://developer.github.com/v3/repos/statuses/

[...] Users with push access can create commit statuses for a given ref [...]

roji commented 10 years ago

I just spent an hour on this 404 before realizing my user had no push access. After writing to github about why they don't respond with a 403 instead of a 404, a developer replied immediately with this:

I know it's confusing, and it still trips me up all the time. We do this to avoid leaking information about private repositories. It's basically our version of "we can neither confirm nor deny extraterrestrial activity in this area."

It makes sense to me, even if it makes public repository users suffer a little because of the private ones. Oh well.

I'd suggest making this very clear in the error message ("your user may not have push access"), and regardless, it would be nice to have errors in the build log and not just in the teamcity server log.

jonnyzzz commented 10 years ago

This is the part of #17