Gitlab - get env info for a project - gitlab

I'm trying to get environment info given project id and environment id. I'm following Gitlab doc. Right now I'm able to get all environments by a project id with the following call: http://my_gitlab_url/gitlab/api/v4/projects/27/environments. I get correctly the result:
[
{
"id": 46,
"name": "my_first_env",
"slug": "my_first_env",
"external_url": null,
"project": {
"id": 27,
...
}
},
{
"id": 47,
"name": "my_second_env",
"slug": "my_second_env",
"external_url": null,
"project": {
"id": 27,
...
}
}
]
Then I want to get a single env info, so using the previous informations I call: http://my_gitlab_url/gitlab/api/v4/projects/27/environments/47 but I receive a 404 error. That is strange because I got the pair (project, env) from the previous call. Using the env name or slug won't work either. Also in the env settings page: http://my_gitlab_url/gitlab/my_project/environments/47/edit I only see the name section, no ID. Plus, in this last URL the project ID matches the one I'm using. Am I missing something? Where else can I find the env ID?

Your requests to the API are perfectly fine, you are using the correct environment ID.
However, the "single environment" endpoint was added in version 11.11 and is not yet available in 11.08. You need to update the GitLab server.

Related

How to get the group ID of a specific submodule?

I'm a beginner with GitLab, I'm being asked to get the group ID of each submodule. But when I click on one for example, all I see is the Project ID.
Here we have a list of all submodules:
Clicking on RxAT1LGC submodule as an example:
Is there a way to get the group ID of each submodule?
You could use the Get project API (through curl or using the glab CLI) in order to get the group of groups sharing that project:
...
"shared_with_groups": [
{
"group_id": 4,
"group_name": "Twitter",
"group_full_path": "twitter",
"group_access_level": 30
},
{
"group_id": 3,
"group_name": "Gitlab Org",
"group_full_path": "gitlab-org",
"group_access_level": 10
}
],
...

How to create a fork of a parent repository using Azure DevOps REST API?

How can we create a new repository copying all the contents from a parent repository? I have tried forking an existing repository, but the REST API is throwing 400 Bad Request exception.
The sample request provided in the Microsoft document here is not working as expected and is throwing below exception.
{
"$id": "1",
"innerException": null,
"message": "A team project ID or name is required in the URL or request body.\r\nParameter name: ProjectReference",
"typeName": "Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer",
"typeKey": "InvalidArgumentValueException",
"errorCode": 0,
"eventId": 0
}
How to create a fork of a parent repository using Azure DevOps REST API?
I could reproduce this issue with the sample request body.
To resolve this issue, please try to replace the name with ID of the project:
{
"name": "forkRepository",
"project": {
"id": "MyFirstProject_ID"
},
"parentRepository": {
"name": "MyFirstRepo",
"project": {
"id": "MyFirstProject_ID"
}
}
}
My test result:
And the fork repo:

Azure DevOps API TFS: How to get a file history if it was renamed and/or branched?

Is this possible somehow to get a file history (all related changesets) with API request if the file was branched or/and renamed?
For example, if I need to find a history of the object in Azure DevOps UI I can search this object in the project, in a certain path like this:
And if I need to find the first appearance of the object in a repository, I can get it by expanding a "branch and rename" history
There is a need to get this information via API requests.
I had tried to find some API requests which can do it, but found only the requests which can return only the changesets which are on the first picture, where the object has the same name and is located under the path defined in the search parameter - there is no information about renaming/branching operations.
GET https://dev.azure.com/Contoso/_apis/tfvc/changesets?api-version=6.0&searchCriteria.itemPath=$/Contoso/Trunk/Main/Metadata/Application_Ext_Contoso/Application_Ext_Contoso/AxSecurityPrivilege/Entity.xml
returns only 3 changesets - 2162, 2161, 391
POST https://dev.azure.com/Contoso/Contoso/_api/_versioncontrol/history?api-version=6.0
With the body request
{
"repositoryId":"",
"searchCriteria":"{\"itemPaths\":[\"$/Contoso/Trunk/Main/Metadata/Application_Ext_Contoso/Application_Ext_Contoso/AxSecurityPrivilege/Entity.xml\" ], \"followRenames\" : true ,\"top\":50}",
"includeSourceRename" : true
}
Also returns only 3 changesets, it only finds a specific item path, I tried to experiment with includeSourceRename and followRenames , but they do not work as I expected.
POST https://almsearch.dev.azure.com/Contoso/Contoso/_apis/search/codesearchresults?api-version=6.0-preview.1
with the body
{
"searchText": "Entity.xml",
"$skip": 0,
"$top": 25,
"filters": {
"Project": [
"Contoso"
],
"Repository": [
"$/Contoso"
],
"Path": [
"$/Contoso/"
]
},
"$orderBy": [
{
"field": "filename",
"sortOrder": "ASC"
}
],
"includeFacets": true
}
Also returns information only about 3 changesets.
Are there some approaches to get this information from the API request?

How to retrieve Work Item linked to specific commit - Azure Devops REST API

I need to be able to retrieve the linked work item of any given specific commit. I'm currently using the following api call
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.0
with the following response
{
"parents": [],
"treeId": "7fa1a3523ffef51c525ea476bffff7d648b8cb3d",
"push": {
"pushedBy": {
"id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"displayName": "Chuck Reinhart",
"uniqueName": "fabrikamfiber3#hotmail.com",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
},
"pushId": 1,
"date": "2014-01-29T23:33:15.2434002Z"
},
"commitId": "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"author": {
"name": "Chuck Reinhart",
"email": "fabrikamfiber3#hotmail.com",
"date": "2014-01-29T23:32:09Z"
},
"committer": {
"name": "Chuck Reinhart",
"email": "fabrikamfiber3#hotmail.com",
"date": "2014-01-29T23:32:09Z"
},
"comment": "First cut\n",
"url": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"remoteUrl": "https://dev.azure.com/fabrikam/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"_links": {
"self": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"repository": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
},
"changes": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4/changes"
},
"web": {
"href": "https://dev.azure.com/fabrikam/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"tree": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/7fa1a3523ffef51c525ea476bffff7d648b8cb3d"
}
}
}
from https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get?view=azure-devops-rest-5.0 and am missing a way to see what work item its linked to or if it is linked at all. Does anyone know of a way to get this information? Thanks
You could use the Get Commits API, docs here. The base request looks like:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.0
You could then add the following parameters:
fromCommitId - string - If provided, a lower bound for filtering commits alphabetically
toCommitId - string - If provided, an upper bound for filtering commits alphabetically
includeWorkItems - boolean - Whether to include linked work items
So that your final query would look something like, with your toCommitId and fromCommitId parameters being your commit id that you are after (the documentation doesn't specificy whether these are inclusive or exclusive so your might have to tweak this slightly):
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?includeWorkItems=true&.toCommitId={searchCriteria.toCommitId}&fromCommitId={searchCriteria.fromCommitId}&api-version=5.0
The result should contain a workItems property inside each commit object of the response as per this documentation.
Note:
Parameters that use the searchCriteria prefix in their name can be specified without it as query parameters, e.g. searchCriteria.$top -> $top
There is also:
ids - array - If provided, specifies the exact commit ids of the commits to fetch. May not be combined with other parameters.
Which could allow you to forgo passing in the to and from commit ids but the docs state that it May not be combined with other parameters - even though the example request does combine it with other parameters. I haven't tried this myself so please do comment when you find out whether you go with from-to id or just ids.
OPs action
The OP ended up using the following request as they didn't mind all commits being returned:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?includeWorkItems=true&api-version=5.0

Chef overwrite default attributes of a cookbook

The git cookbook has an error in the url that it uses to download the appropriate version. The url is set in the attributes file as a default attribute so I figured I could just overwrite the url with something static but it does not work. Here is the code from the git cookbook:
case node['platform_family']
when 'windows'
default['git']['version'] = '2.8.1'
if node['kernel']['machine'] == 'x86_64'
default['git']['architecture'] = '64'
default['git']['checksum'] = '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb'
else
default['git']['architecture'] = '32'
default['git']['checksum'] = '17418c2e507243b9c98db161e9e5e8041d958b93ce6078530569b8edaec6b8a4'
end
default['git']['url'] = 'https://github.com/git-for-windows/git/releases/download/v%{version}.windows.1/Git-%{version}-%{architecture}-bit.exe'
The cookbook is being included as a dependency in my metadata.rb file and used as a resource in my recipe. It is not part of the runlist. I've tried overwriting the url in my role file like so
"name": "web",
"description": "Web Server Role.",
"json_class": "Chef::Role",
"default_attributes": {
"chef_client": {
"interval": 300,
"splay": 60
},
"git": {
"url": "a test string"
}
},...
That did not work, so I tried adding it to the attributes file of my recipe as a default value, and when that did not work, I tried the override! method which still did not work.
I think the problem is due to the fact that the attribute does not exist when I have declared it, and it gets overwritten by the git recipe.
I don't know how to get around that.
Use override_attributes instead of default_attributes:
"name": "web",
"description": "Web Server Role.",
"json_class": "Chef::Role",
"default_attributes": {
"chef_client": {
"interval": 300,
"splay": 60
}
},
"override_attributes": {
"git": {
"url": "a test string"
}
},...

Resources