How do I add a heroku deployhook:email using API? - api

I have been able to add a deployhook (for email and IRC) using the heroku cli (sdk). I would like to be able to add or update the email values (receipient etc) using the API. Is this possible? When I try to curl request to add a hook I get an error message noting the need for extra data: receipient, body, etc.

You can find a bit more detail about the different arguments here: https://devcenter.heroku.com/articles/deploy-hooks#email
Once you know what values you want/need you should be able to send it using this:
curl -n -g -X POST 'https://api.heroku.com/apps/MYAPP/addons/deployhooks%3Aemail?config[recipient]=me#example.com&config[subject]="MYAPP%20Deployed"&config[body]="{{user}}%20deployed%20app"'
The arguments:
-n reads credentials from netrc (this should be set by the toolbelt/cli)
-g tells it to not try and interpret the [] and {} in the url
-X POST sets it to be a POST rather than get request
Beyond that it was just a matter of encoding the params properly. I believe of those values recipient is the only required value (and the others have reasonable defaults).
You can only have one deployhook per type and they don't appear to allow updates. So if you need to change it, you'll want to remove the old one and then add another with the updated attributes. You can remove the old one like this:
curl -n -X DELETE 'https://api.heroku.com/apps/MYAPP/addons/deployhooks%3Aemail'

Related

Access Token Curl

On this website:
https://developers.google.com/nest/device-access/authorize
Under Get Access Token
It says "Open a terminal and run the following curl command, replacing oauth2-client-id and oauth2-client-secret with the OAuth2 Client ID and Client Secret from your GCP Credentials, and authorization-code with the code you receive in the previous step:"
I have repeatedly input my oauth2-client-id, oauth2-client-secret and authorization-code. I copy and paste into the Terminal in Raspbian. It always says "Curl(3) URL using bad/illegal format or missing URL". Because I am copying and pasting all my information into the syntax, then copying and pasting the syntax into Terminal, I am at a complete loss for how to proceed.
Is something wrong with the Syntax that this Google document provided?
Google's recommended syntax is shown in the image and on the website I gave a link to.
enter image description here
.... made some progress here.
Rather than utilising the copy-code from Google, directly from the page, I copied and pasted onto "TextMate" and joined the 5 rows command into a single row.
I basically went at the beginning of each row (in TextMate) and backspace'd to the previous row, until the command was a single line one.
I then copied the single line command and pasted it into Terminal.
This is removing the previous error, at least the command is going through, I get most of the responses from the server.
I am still getting an error, which I am trying to figure out: "error" : "unsupported_grant_type".
The command includes "... grant_type=authorization_code..." within the command.

Getting names of all private repos through GitHub API

I'm trying to get a list of all names in a repo that I have access to. I tried running:
curl -u username:pw -X GET https://api.github.com/orgs/org_name/repos?per_page=100 >> list.txt
but I get the error: zsh: no matches found: https://api.github.com/org/org_name/repos?per_page=100
All I want is a list of the repos... no other information. Can't seem to figure it out. I'm new to programming and started using API like.. 1 hour ago? Any advice would be helpful.
Your shell (zsh) is interpreting the URL as a path and complaining because it doesn't match any files. You can solve this by placing quotes around it. In this case, either single or double quotes will work.

API Timezone Parameter ignored by CURL

I have a Problem with the URL-Encoded Timezone parameter (Europe%2FBerlin) in an API request:
My API Request to get a data feed from thingspeak:
https://api.thingspeak.com/channels/CHANNELID/feed.csv?api_key=APIKEY&timezone=Europe%2FBerlin
If I post this into the Browser the Timezone Parameter is recognised and displayed correctly.
If I put the request into a curl command like this:
curl -o /Path/To/File.csv https://api.thingspeak.com/channels/CHANNELID/feed.csv?api_key=APIKEY&timezone=Europe%2FBerlin
... the timezone parameter is ignored.
How can this be fixed?
By quoting the URL. Put it within double quotes.
The '&'-symbol is treated special by the shell and is used to put the command in the background and then treat what's on the right side of it as a second, separate command.

Schedule or trigger jobs in gitlab-ci

I want to run a heavy test only once per day in Gitlab-ci. Is it possible schedule a job? Or is it possible to set it to manual and trigger it using the API?
It's possible to schedule a pipeline since GitLab 9.1, see:
https://docs.gitlab.com/ce/user/project/pipelines/schedules.html
Currently (i.e. with version 9.2) it can be configured as follows:
Navigate to your project's Pipelines ➔ Schedules and click the New Schedule button.
Fill in the form
Hit Save pipeline schedule for the changes to take effect.
It's a patch up job, but you could use triggers with a if statement :
test_app:
stage: test
script:
- if [ -n "${DO_TESTS}" ]; then make test; fi
And define the variable in the cron that make the call :
curl --request POST \
--form token=TOKEN \
--form ref=master \
--form "variables[DO_TESTS]=true" \
https://gitlab.example.com/api/v3/projects/9/trigger/builds
See the doc : https://docs.gitlab.com/ce/ci/triggers/README.html
This is possible, and will be improved in GitLab 11.6 (Dec. 22nd)
See gitlab-org/gitlab-ce issue 20422:
Currently all variables are shown in UI:
http://docs.gitlab.com/ce/ci/triggers/README.html#pass-build-variables-to-a-trigger
This is sometimes problematic, e.g. when you pass individual secrets to the build, which could not be placed in a protected variable and should not be visible to all team members.
It can also be problematic even for some non-protected variables if they are unintentionally passed around in a screenshot/screen sharing.
Proposal
Variable names will still be visible by default
Variables values will be censored by default with asterix *******
Variable values are toggle-able with a button
The button is only available to maintainers

Git - how do I view the change history of a method/function?

So I found the question about how to view the change history of a file, but the change history of this particular file is huge and I'm really only interested in the changes of a particular method. So would it be possible to see the change history for just that particular method?
I know this would require git to analyze the code and that the analysis would be different for different languages, but method/function declarations look very similar in most languages, so I thought maybe someone has implemented this feature.
The language I'm currently working with is Objective-C and the SCM I'm currently using is git, but I would be interested to know if this feature exists for any SCM/language.
Recent versions of git log learned a special form of the -L parameter:
-L :<funcname>:<file>
Trace the evolution of the line range given by "<start>,<end>" (or the function name regex <funcname>) within the <file>. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments. You can specify this option more than once.
...
If “:<funcname>” is given in place of <start> and <end>, it is a regular expression that denotes the range from the first funcname line that matches <funcname>, up to the next funcname line. “:<funcname>” searches from the end of the previous -L range, if any, otherwise from the start of file. “^:<funcname>” searches from the start of file.
In other words: if you ask Git to git log -L :myfunction:path/to/myfile.c, it will now happily print the change history of that function.
Using git gui blame is hard to make use of in scripts, and whilst git log -G and git log --pickaxe can each show you when the method definition appeared or disappeared, I haven't found any way to make them list all changes made to the body of your method.
However, you can use gitattributes and the textconv property to piece together a solution that does just that. Although these features were originally intended to help you work with binary files, they work just as well here.
The key is to have Git remove from the file all lines except the ones you're interested in before doing any diff operations. Then git log, git diff, etc. will see only the area you're interested in.
Here's the outline of what I do in another language; you can tweak it for your own needs.
Write a short shell script (or other program) that takes one argument -- the name of a source file -- and outputs only the interesting part of that file (or nothing if none of it is interesting). For example, you might use sed as follows:
#!/bin/sh
sed -n -e '/^int my_func(/,/^}/ p' "$1"
Define a Git textconv filter for your new script. (See the gitattributes man page for more details.) The name of the filter and the location of the command can be anything you like.
$ git config diff.my_filter.textconv /path/to/my_script
Tell Git to use that filter before calculating diffs for the file in question.
$ echo "my_file diff=my_filter" >> .gitattributes
Now, if you use -G. (note the .) to list all the commits that produce visible changes when your filter is applied, you will have exactly those commits that you're interested in. Any other options that use Git's diff routines, such as --patch, will also get this restricted view.
$ git log -G. --patch my_file
Voilà!
One useful improvement you might want to make is to have your filter script take a method name as its first argument (and the file as its second). This lets you specify a new method of interest just by calling git config, rather than having to edit your script. For example, you might say:
$ git config diff.my_filter.textconv "/path/to/my_command other_func"
Of course, the filter script can do whatever you like, take more arguments, or whatever: there's a lot of flexibility beyond what I've shown here.
The closest thing you can do is to determine the position of your function in the file (e.g. say your function i_am_buggy is at lines 241-263 of foo/bar.c), then run something to the effect of:
git log -p -L 200,300:foo/bar.c
This will open less (or an equivalent pager). Now you can type in /i_am_buggy (or your pager equivalent) and start stepping through the changes.
This might even work, depending on your code style:
git log -p -L /int i_am_buggy\(/,+30:foo/bar.c
This limits the search from the first hit of that regex (ideally your function declaration) to thirty lines after that. The end argument can also be a regexp, although detecting that with regexp's is an iffier proposition.
git log has an option '-G' could be used to find all differences.
-G Look for differences whose added or removed line matches the
given <regex>.
Just give it a proper regex of the function name you care about. For example,
$ git log --oneline -G'^int commit_tree'
40d52ff make commit_tree a library function
81b50f3 Move 'builtin-*' into a 'builtin/' subdirectory
7b9c0a6 git-commit-tree: make it usable from other builtins
The correct way is to use git log -L :function:path/to/file as explained in eckes answer.
But in addition, if your function is very long, you may want to see only the changes that various commit had introduced, not the whole function lines, included unmodified, for each commit that maybe touch only one of these lines. Like a normal diff does.
Normally git log can view differences with -p, but this not work with -L.
So you have to grep git log -L to show only involved lines and commits/files header to contextualize them. The trick here is to match only terminal colored lines, adding --color switch, with a regex. Finally:
git log -L :function:path/to/file --color | grep --color=never -E -e "^(^[\[[0-9;]*[a-zA-Z])+" -3
Note that ^[ should be actual, literal ^[. You can type them by pressing ^V^[ in bash, that is Ctrl + V, Ctrl + [. Reference here.
Also last -3 switch, allows to print 3 lines of output context, before and after each matched line. You may want to adjust it to your needs.
Show function history with git log -L :<funcname>:<file> as showed in eckes's answer and git doc
If it shows nothing, refer to Defining a custom hunk-header to add something like *.java diff=java to the .gitattributes file to support your language.
Show function history between commits with git log commit1..commit2 -L :functionName:filePath
Show overloaded function history (there may be many function with same name, but with different parameters) with git log -L :sum\(double:filepath
git blame shows you who last changed each line of the file; you can specify the lines to examine so as to avoid getting the history of lines outside your function.