Programmatically test connection in JetBrains/commit-status-publisher bundled plugin

Hello,

I'm using TeamCity Enterprise 2018.1.3 (build 58658) and I wonder if there is a way to test a connection between TC and Github programmatically through the commit-status-publisher plugin.

I'm able to fill those fields using the TC REST API, but couldn't found anything about testing the just defined connection to confirm if the data is correct. Any hint is appreciate it.

 

2 comments
Comment actions Permalink
Official comment

Hi,

It is impossible to invoke actual Test Connection functionality of Commit Status Publisher via REST API. You can create a feature request in our issue tracker and describe your case in details: https://youtrack.jetbrains.com/issues/TW 

There are few imperfect workarounds:

One option is to actually start a build on some commit (via TeamCity REST API) and check if a status of a commit is published (via GitHub REST or GraphQL API as in https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref for example).

Another option is to post the status using the access token from your code (as in https://developer.github.com/v3/repos/statuses/#create-a-status).

And the last possibility I can think of is to simulate what Commit Status Publisher's test connection actually does (via GitHub REST or GraphQL API as well): 
- query the repository (as in https://developer.github.com/v3/repos/#get)
- check if the response contains correct repository name (this is not essential though)
- check if a push permission flag is set in the repository information

The latter two options will only test if there is enough permissions associated with your token to publish statuses in this particular repository. 

Comment actions Permalink

Hello Anton,

Thank you for your help, I finally deployed your latest suggestion, I tested the credentials directly against the github api, I think in general it would make sense to test the connection from within the TC API but the current solution isn't that hard either, so I'll leave it like that.

0

Please sign in to leave a comment.