Is it possible to add a remote with GitHub API? - api

Is it possible to add a remote with GitHub API same as git remote add upstream <repository URL>? I have read the docs but I can not find the way.
ref
- How to update a fork from it's original via the Github API
Thanks in advance.

# Get original hash
curl "https://api.github.com/repos/:original/:repo/git/refs/heads/master"
# Follow upstrem change
curl -X POST \
-H "Authorization: token <TOKEN>" \
--data '{"base":"<fork/BRANCH>","head":"<original/HASH>"}' \
"https://api.github.com/repos/:fork/:repo/test_project/merges"

Related

curl command to tarball ALL organizations repos thru API

Was making a bash script to backup organization's repos (private included) convert them into a tar file and then send off to s3 bucket.
curl -H "Authorization: token {PAT}" -L https://api.github.com/repos/{org}/tarball/main > main.tar.gz
When I do this command with one single repo it works, but my task was to have it grab all 100+ repos in the organization. Any thoughts of what I am missing?
I don't think that there is any API from GitHub to provide your desired HTTP call out of the box.
You can try to create a Bash/PowerShell script to:
List the organization:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/orgs/ORG/repos
(reference: https://docs.github.com/en/rest/repos/repos#list-organization-repositories)
Take the result and convert it to an array.
For each element in the array, run your command:
curl -H "Authorization: token {PAT}" -L
https://api.github.com/repos/{org}/tarball/main > main.tar.gz

Nexmo API change on Text to Speech?

For a very long time I've been using the following to send text-to-speech alerts from my applications.
curl 'https://api-us-1.nexmo.com/tts/json' \
-d api_key=****** \
-d api_secret=****** \
-d to=0035193xxxxxxx \
-d from=0035193xxxxxxx \
--data-urlencode 'text=Alert! Check Something... ' \
-d repeat=2 \
-d voice="male" \
Very recently the service has stopped working for some carriers.
While going over Nexmo docs I can't see the /tts/json API documented.
Anyone knows what happened?
Is the /tts/json API still usable?
The /v1/calls API is absolutelly overkill for my needs.
Unfortunately that API was sunset quite a while ago and replaced with the newer Voice API.
https://developer.nexmo.com/voice/voice-api/code-snippets/make-an-outbound-call-with-ncco would the closest alternative with the Voice API. The biggest change is switching to using a JWT for authentication versus the key/secret auth the older API used.
If you have the Nexmo CLI installed you can generate a JWT as part of a script. The following should work:
#!/bin/bash
#
# Send voice message to a user
#
# ./script.sh <number to call> <vonage number> "<message to speak>"
PATH_TO_PRIVATE_KEY=<path to private key>
VONAGE_APPLICATION_ID=<application ID>
TO_NUMBER=$1
VONAGE_NUMBER=$2
MESSAGE=$3
JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$VONAGE_APPLICATION_ID)
curl -X POST https://api.nexmo.com/v1/calls\
-H "Authorization: Bearer "$JWT\
-H "Content-Type: application/json"\
-d "{\"to\":[{\"type\": \"phone\",\"number\": \"$TO_NUMBER\"}],
\"from\": {\"type\": \"phone\",\"number\": \"$VONAGE_NUMBER\"},
\"ncco\": [
{
\"action\": \"talk\",
\"text\": \"$MESSAGE\"
}
]}"

Using CURL to list github repository tree (github API)

Using the github API, you can get a repository tree using (example done with CURL):
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/git/trees/{tree_sha}
Assuming I have a repo called dev by owner NewCo, and I want to list the repo tree called XXXX, I would:
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/NewCo/dev/git/trees/{tree_sha}
How can I find out the {tree_sha} value for tree XXXX? Any idea where can I find out this value?
You can use a commit sha from the commits endpoint for that: /repos/{owner}/{repo}/commits. For example:
#!/usr/bin/env bash
set -e
owner=zacanger
repo=fetchyeah
sha=$(curl -s -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$owner/$repo/commits?per_page=1 \
| jq -r '.[0].sha')
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$owner/$repo/git/trees/$sha
You could also use the pull requests API, or any other endpoint that returns commit info (meaning, most of them except for user and org APIs).

Release a version in Jira using API

I want to know if is it possible to release a version in Jira ?
How can I do this using Rest API ?
I've already read this : https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-release-a-version-using-REST-api/qaq-p/563559 
But have there been any update?
Thanks in advance for your help
This curl put request updates an existing version and tags as released
curl --location --request PUT
'https://yourcompany.atlassian.net/rest/api/3/version/VERSION_ID' \
--header 'Authorization: Basic YOUR_BASIC_AUTH' \
--data-raw '{
"released": true
}'

Bamboo Trigger Deployment plan with variables

Im trying to deploy a plan that has artefacts from external service for this I want to download via curl those files that I will pass as variables... however I am not able to set programmaticly the variables with the deploymet call
curl -k -u user:passord -X POST -d "bamboo.myVariable=someurl" BASE_BAMBOO_URL/bamboo/rest/api/latest/queue/PROJECT-ID
Trying to do the same with the deployment API fails
curl BASE_BAMBOO_URL/bamboo/rest/api/latest/deploy/project/1321123123 -u user:passord-X POST -d "bamboo.myVariable=callMEwithDATA"
Trying to add that into the API fails as does trying to pass it thru JSON
curl -X POST BASE_BAMBOO/bamboo/rest/api/latest/deploy/project/1320058 -u user:passord -H "Accepts: application/json" -H "Content-Type: application/json" -d '{"name":"release-1", "myVariable":"ARTEFACT_URL"}'
To continue with a request the variables have to be passed as query params... a sad sad reality is that the Bamboo API is very messed up
bamboourl&executeAllStages=true&bamboo.variable.MYVAR=1234