The get repository api (link) works like "search". For example, when I have "foo-bar" repository and I use /repos/MY_NAME/foo it returns foo-bar.
There seems to be no option for disabling this lenient repo name.
Search API just returns more than one item that worsk for the :repo
Related
I am trying to fetch the list of all build items in Azure, and using Postman the following URL shows me the result:
https://dev.azure.com/MyOrganization/MyProject/_apis/build/builds?api-version=6.0
But there is one problem, the query shows me the build for all our company projects whereas I am only intersted in one
The query returns for all projects, but I am only interested in build for Project B
How can I specify this information in the API? I tried the filters and it doesn't work.
Also the same for tags
If you take a look at the API Build List documentation, you can see the optional parameters that can be passed to this request
In this case, you would want to filter on builds from the project B repository, which requires the repositoryType parameter to be passed as well. As such you'd be looking to call
https://dev.azure.com/{organization}/{project}/_apis/build/builds?repositoryID={repoID}&repositoryType=Git&api-version=6.0
Where the repoID can be found be going into project settings-->repository, clicking the project B repo and copying the value that appears in the website URL after repo=
Related problem: How do I find the default branch for a repository using the Github v3 API
Different from the related problem, I want to list the files of the default branch.
The API I know to list files of the master branch is:
https://api.github.com/repos/owner/repo_name/git/trees/master
However, the default branch name could be main.
Is there a way to list files of the default branch through only one query?
You could use HEAD simply (which refers to the default remote branch).
I tried it using gh api after a (gh auth login)
gh api repos/owner/repo_name/git/trees/HEAD
Example:
gh api repos/VonC/gitcred/git/trees/HEAD --jq ".tree[].path"
In a GitLab issue, you can associate a branch with an issue, and in the issue there will be the line
#whoever created the branch branchname to address this issue.
Is there a way of getting that branch using the issues API? I'm trying to set up an automation script that will merge all branches associated with issues that have a certain label into the prod branch, then push the result as a development brnach so I can deploy that to a dev environment. I don't want to use merge requests as they will be used when the dev work is complete and ready to be merged for deployment to production.
Unfortunately, there currently is no official API to fetch an issue's related branches.
Some possible ways you can work around this:
Use the notes API
When a user uses the issue interface to create the branch, you will see a system message, like you mention. This message will be present in the notes API for the issue.
Example using the python-gitlab library:
import re
...
branch_note_pattern = '^created branch \[\`(.*)\`\].*to address this issue'
issue = project.issues.get(ISSUE_NUMBER)
all_notes = list(issue.notes.list(as_list=False))
system_notes = [note for note in all_notes if note.system]
related_branches = []
for note in system_notes:
match = re.match(branch_note_pattern, note.body):
if match:
branch = match.groups()[0]
related_branches.append(branch)
print('BRANCHES RELATED TO ISSUE', ISSUE_NUMBER)
for branch_name in related_branches:
print(branch_name)
However, it is possible to have a related branch without that note appearing because the related branches is just based on naming convention. So, if someone just creates a branch with named like <issue_number>-some-branch-name then it will show up as a related branch, but there will not be a system message in the API.
So, if you rely on the notes API, you may miss related branches created manually.
Use the unofficial frontend API
The issues controller only returns related branches for the purposes of the frontend to render as HTML.
If you request /<:project_url>/-/issues/<:issue_number>/related_branches?format=json you will get a JSON response containing the HTML for the frontend to insert in the issue view. You can parse this HTML to get the related branches.
This will reliably fetch the same related branches you'll see in the UI, but is more work to implement, and is fragile because the API is not guaranteed to be stable between versions of GitLab.
I am trying to list the files present on an enterprise GitHub repository. I tried using GitHub API but base URL for it is
api.github.com where as base URL would be different for me and when I put that URL it says couldn't resolve. How can I achieve it for a URL in below format
https://company.net/org/reponame
Below example works for me but the URL that I have it doesn't work
curl -k https://api.github.com/user/repo?refs=master
For an on-premise GitHub Enterprise, the documentation mentions
REST API endpoints — except Management Console API endpoints — are prefixed with the following URL:
http(s)://[hostname]/api/v3
In your case: https://company.net/api/v3
From there, using the Git Database API -- list tree, you can list all files, as illustrated here.
I am trying to get all branches for a project with
https://dev.azure.com/$organization/$project/_apis/tfvc/branches?&api-
version=5.0
I use the credentials, organization, and project variables in other queries that are working. The request format is based off the example here
https://learn.microsoft.com/en-us/rest/api/azure/devops/tfvc/branches/get?view=azure-devops-rest-5.0
The response I am getting is
count value
----- -----
0 {}
when there are many branches in the repository.
Should I be specifying the repository somewhere? Or what else? Thanks!
First you need to confirm which type of repository you need to use rest API to get branch from, git or tfvc.
If you want to get branches from a tfvc repo, then use the rest api as you refer to in your case.
But, you need to be aware that if the count you want to return is not 0, you should ensure that there are branches in your tfvc repo, not just folders and files.
To convert the folder in tfvc repo to branch, you can convert it in vs source control explorer. For details, please refer to this docs.
If you want to get branches from a git repo, you need to use the rest API as follows.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=5.0