How to post a message to the github api using hub api? - github

I want to use hub to create some automation script but can't figure out how to post a message to the api. More specifically it is this api endpoint I want to post to: https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key
I've tried the following:
hub api user/gpg_keys -F armored_public_key='-----BEGING PGP ....'
hub api user/gpg_keys --raw-field "body={armored_public_key='-----BEGING PGP ....'}
None of the above work, the response back is:
{"message":"Not Found","documentation_url":"https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key"}
which is not very helpful. I thought that -F meant fields within the payload, but I guess I'm wrong.
So how do I post a message with a body using hub api?
UPDATE
I did download the repo to create a modified version that has some more logging, but can't figure out what's wrong. Everything looks good from what I understand in how the request is made.

Looking through the code I found the reason to why this is. It seems like it is hard coded that you should only get the repo scopes when you log in the first time. If you use a token you've created yourself that has more access everything will work as it should.

Related

How to create a comment with data from endpoint?

At my company, we have a CLI which allows our customers to upload data to our backend solution. The CLI runs on PR changes within a job. Let's assume the uploaded data looks like this:
{
name: "John",
age: 20,
}
Once the upload is completed, I'd like to create a comment on the PR with to following body:
John is 20 years old.
I've found the following ways to do this:
GitHub App (a bot)
GitHub OAuth App
Personal Access Token
GITHUB_TOKEN
GitHub App
The GitHub App needs to do the following things:
Fetch the data via a user-specific API key
Create a comment
I already created a comment via a bot, but I have no clue how to fetch the data.
As far as my understanding goes, I'd like other users to be able to install this GitHub app from the marketplace to work out of the box. From the ProBot Docs I understand that the bot operates on a webhook basis. Meaning I need to subscribe to a 'job completed' event (not sure if that's the correct name but I think you get the idea) and then fetch the data via a user-specific API we are providing on our platform. However, I see no way for the user of our App to configure an API key (or any form of secret) so the bot can make authenticated requests to our endpoints.
I'd prefer to use GitHub App because the comment coming from the bot would have our company branding and also an indicator that this comment has been created by the integration.
OAuth App
I already tested this by using Postman, however, the comment looks like it's coming from a specific user. Therefore, it has no company branding and it's not clear that an integration created the comment. However, the great part is that we could integrate this with our application, so our backend could create the comment once the data is received.
What I like about this approach is that we also need to implement such a feature for GitLab, Azure, etc, and using OAuth likely scales well with the other providers in comparison to the GitHub app, which is GitHub-specific.
Personal Access Token
Works pretty much like the OAuth App, but instead of our backend creating the comment, the comment is created by the CLI (and the access token is passed into the CLI). However, I think this approach is a bit sketchy.
GITHUB_TOKEN
While I haven't tried this yet, I assume that the token has limited but sufficient permissions to create a comment. As of now, I don't know what the comment will look like, but I think we can rather safely pass this into the CLI to create the comment from there. Since the permissions are limited and the token is invalidated after the workflow I see limited risk for the user of our CLI (and services).
Edit: The comment is coming from the github-actions bot, which is not the branding we are looking for, but it's clear that the comment has been created by the integration.
Questions
What's the best way to accomplish what I am trying?
Is there any way I can make this work with GitHub Apps (aka bots)?

How to use zapi for zephyr jira

I want to create an automated process for my tests. I am using jira and zapi. I want to try interacting with my tests in zephyr-jira using postman api. The thing is there isn't much documentation on how to use zapi.
First thing, what is the url? Is it test.atlassian.net/jira/?/?/?/apifunction?
Second thing, I can generate an access key and secret key but it seems like I also need an authorization jwt token, how can I generate one that I can use via postman?
Any help would be appriciated.
The apiary documentation is here https://getzephyr.docs.apiary.io/#
That will help you assemble the requests. What the requests and responses actually represent is still confusing (to me, anyway).
In postman: https://{{JiraHost}}/rest/zapi/latest/
some examples:
https://{{JiraHost}}/rest/zapi/latest/cycle/830
https://{{JiraHost}}/rest/zapi/latest/cycle?versionId=21689

How to get pull requests references for an issue

Given a GitHub issue, is there any way to get the pull requests that reference to that issue via API?
That info is showed in the GitHub html page but I can't see nothing in the API documentation.
Is it really possible?
is there any way to get the pull requests that reference to that issue via API
Not directly.
Even the reverse is not possible, as a pull request has a link 'issue' pointing to... itself.
But as mentioned in the issue API:
In the past, pull requests and issues were more closely aligned than they are now.
As far as the API is concerned, every pull request is an issue, but not every issue is a pull request.
This endpoint may also return pull requests in the response. If an issue is a pull request, the object will include a pull_request key.
So you would need to list the comments of a pull request (using the Issue Comments API since comments on PR are done with it), and parse said comment to find a reference to an issue.

Why can't I programmatically add and delete topics using the Kafka Administration REST API for Bluemix's Message Hub?

I'm calling the IBM Bluemix Administration API for Message Hub (aka Kafka), as described here.
Calling the endpoint https://kafka-admin-prod02.messagehub.services.eu-gb.bluemix.net:443/topics (using an appropriate X-Auth-Token value corresponding to our API key, and a GET verb) seems to work - it returns a list of the topics we've manually configured in the Bluemix Message Hub admin screen.
However, calling the same URL with the verb POST and a body of {name: 'mynewtopicname'} and a Content-Type of application/json (this appears to be the correct syntax, according to the Swagger docs for the API) doesn't work - I get a result of "HTTP 405 Method Not Allowed". That seems to happen whether I use GET, PUT, POST or DELETE (which also means I cannot delete a topic).
Am I doing something wrong?
(I'm using Message Hub on the UK Bluemix instance, if it's relevant).
To create topics you need to do a POST to the URL /admin/topics, not /topics. Give it a try and let me know if it works.

JIRA REST API Oauth dance cannot be implemented with consumer key

I am trying to call the JIRA REST API and get a request token. I have defined an application link in JIRA with consumer key and public key. But when I am trying to request the request-token with the following url
http://localhost:8080//plugins/servlet/oauth/request-token?oauth_consumer_key=consumerKey (which was used in creating the application link)
I am getting the following response
oauth_problem=consumer_key_unknown
How to get rid of this?
This link would be handy if you are using python.
https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src/d625161454d1ca97b4515c6147b093fac9a68f7e/python/app.py?at=default
Also use python centrifi package to get pass sslHandShakeError. ( atlassian root certificate seems to be not from known one )