How can I get the main programming language of a project, using sonarqube API? Or a list of all of the project's programming languages?
Per SonarQube Metric Definitions documentation :
ncloc_language_distribution - Non Commenting Lines of Code Distributed By Language.
Use that with SonarQube WebAPI api/measures (documentation embedded in your SonarQube server) and you should be good to go.
Trying to solve the same problem, I came up with a small shell script that writes a list of all SonarQube project keys and the language distribution for the given project:
#!/bin/bash
API="http://my.sonar-server.com:9000/sonar/api" ### adjust this!
API_LANG_DIST="$API/measures/component?metricKeys=ncloc_language_distribution"
# get a list of all project keys:
projKeys=$(curl -s "$API/projects/index" | jq -r '.[].k')
# for each project key, get the language distribution metric:
for key in ${projKeys}; do
langDist=$(curl -s "${API_LANG_DIST}&componentKey=${key}" | jq '.component.measures[0].value')
printf "%-80s%-80s\n" ${key} ${langDist}
done
The output will be something like this:
com.mycompany:projectA "grvy=75;java=4091"
com.mycompany:projectB "css=1966;java=52770;js=11460;less=1862"
com.mycompany:projectC "css=40185;java=11451;js=13757"
Note: This script makes use of the jq JSON parsing utility. If you do not have it available, you can install it for example via sudo yum install jq.
(Tested on SonarQube 5.6.6 and 6.7.0)
Related
I have to fine-tune the OpenAI model on my custom dataset. I have created the dataset in jsonl format. I use the following commands on windows command line:
set OPENAI_API_KEY=<API key>
openai tools fine_tunes.prepare_data -f "train_data.jsonl"
The above commands run successfully and give me some suggestions for updating jsonl file. After this, I run the following command to fine-tune the 'curie' model.
openai api fine_tunes.create 'openai.api_key = <API key>' -t "train_data.jsonl" -m "curie"
But I am getting following issue:
←[91mError:←[0m Incorrect API key provided: "sk-iQJX*****************************************mux". You can find your API key at https://beta.openai.com. (HTTP status code: 401)
Can anybody help me out with this issue.
This is a common issue with an earlier version of the openai's CLI. If you haven't already, make sure you upgrade to the most recent version by doing
pip install --upgrade openai
One possible workaround is to just use a python script to do what you would normally do in the CLI.
# To train a model:
import os
import openai
os.environ["OPENAI_API_KEY"] = "sk-iQJX*****************************************mux"
os.system("openai api fine_tunes.create -t train_data.jsonl -m curie")
When assigning the API key in command line, dont use double quotes like:
API_KEY=ab-123123123123123231
This will solve the issue
I'm trying to use the Kube OpenAPI tool openapi-gen to generate OpenAPI specs for Google's Config Connector.
I'm relatively new to Go, so I'm not sure whether this is a configuration error on my part or if I'm simply using it wrong.
I've cloned the Kube OpenAPI repo, and inside of that directory I've cloned the Config Connector repo, for simplicity.
This is what's happening when I try to generate an OpenAPI spec file.
$ go run cmd/openapi-gen/openapi-gen.go -i ./k8s-config-connector/pkg/apis/serviceusage/v1beta1 -p foo.com/foo -h ./boilerplate/boilerplate.go.txt
E0811 16:45:57.516697 22683 openapi.go:309] Error when generating: TypeMeta, TypeMeta invalid type
2021/08/11 16:45:57 OpenAPI code generation error: Failed executing generator: some packages had errors:
failed to generate default in ./k8s-config-connector/pkg/apis/serviceusage/v1beta1.Service: TypeMeta: not sure how to enforce default for Unsupported
exit status 1
What's going on here?
Here are some troubleshooting steps:
1 - GOROOT variable should be set and point to root of go installation
2- Operator-sdk depended on it being exported as an environment variable. Run the below command
export GOROOT=$(go env GOROOT)
when using the operator-sdk, it is necessary to either (a) set GOROOT in your environment, or (b) use the same GOROOT that was used to build the operator-sdk binary.
Refer to the link for additional information.
First of all: I am somewhat new to cloud build. Compared to previously used methods, I find it a wrenching, unripe and fairly annoying framework. Endless time is spend getting builders to work that supposedly work out of the box (like the helm builder for example), and it's limitations are astonishing and frustrating. Perhaps the following problem is a good example:
I would like to build and push a docker image. According to the documentation, the images to be pushed to the docker repository at the end (I'm using GCR for this) reside in the following configuration section in my cloudbuild.yaml file:
images:
- 'eu.gcr.io/$PROJECT_ID/my-project:${_TAG}'
- 'eu.gcr.io/$PROJECT_ID/my-project:latest'
I can set the _TAG substitution manually by using the section:
substitutions:
_TAG: x.y.z
but that means I have to manually fix the version number in this file every time. Worse still: if I branch out, I need to maintain the version number all the time. I have a python project in this case and it uses setuptools, the version is naturally contained in the setup.py file and I can parse it out with no problem. Attempts to parse the number into a specific file and use $(cat VERSION) in the images section fail, because the system claims it can't substitute the $(cat VERSION) part. So how can I overwrite the _TAG variable inside of another build step such, that it appears correct in the 'images' section?
If you are using triggered builds from Cloud Source Repositories, GitHub, or Bitbucket you can tag your commit and use the $TAG_NAME default substitution variable.
images:
- 'eu.gcr.io/$PROJECT_ID/my-project:$TAG_NAME'
- 'eu.gcr.io/$PROJECT_ID/my-project:latest'
On the other hand if you are using the Cloud SDK to submit the Cloud Build build you can provide values with the --substitutions argument:
gcloud builds submit [SOURCE] --config config.yaml --substitutions _TAG=x.y.z
Also I believe you would find this GitOps-style continuous delivery with Cloud Build tutorial very helpful. It explains how to create a continuous integration and delivery (CI/CD) pipeline on Google Cloud Platform using Cloud Build.
You can tag your image with several tags using cloudbuild.yaml and define the Docker build step with:
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:latest'
- .
- '-f'
- Dockerfile.prod
id: Build
And resulting images with:
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:latest'
I'm new to the OpenAPI 3.0.0.
I have successfully created a java client library using an openapi-generator.
But OpenAPI Generator allows the generation of API client libraries (SDK generation), server stubs, documentation. So I want to know is there any commands or steps are available to generate HTML documentation and also to customize the documentation template.
Old question, but for those still bumping into it. OpenApi Generator can do generation of html documentation from your yaml or json definition of your API.
openapi-generator generate -i PathToMyInputDefinitionFile.yaml -g html -o /PathToOutputFolder
Where html is the generator you want to use. Other generators include dynamic-html and html2. Also can emit as markdown. See https://openapi-generator.tech/docs/generators/
If using Docker, a full example would look like this:
docker run --rm -v ${PWD}:/local openapitools/openapi-generator:tagname generate -i /local/input.yaml -g html -o /local
PWD is present working directory (current directory) in the host, which you are mapping on to /local in the container. Adjust 'tagname' to suit, from https://hub.docker.com/r/openapitools/openapi-generator/tags Adjust input.yaml to be your input file yaml definition of your API.
I'm working on a ASP.NET Core WebAPI project and I'm trying to find a way to generate swagger json at build time ?
As i'm working with 4 environments, i'd like to have 4 swagger.json with a different name of my choice, like:
swagger_{appName}dev{buildNumber}.json
swagger_{appName}demo{buildNumber}.json
swagger_{appName}int{buildNumber}.json
swagger_{appName}staging{buildNumber}.json
Is it also possible to edit the fields in the json ? I'd like to edit (depending of the environment) the following fields : host, schemes and basePath.
I'm using Swashbuckle.AspNetCore but it appears it doesn't have an option to do such task or am I wrong ?
Thanks in advance
You have the option of generating OpenApi json file(s) from the command line without deploying using the Swashbuckle.AspNetCore.Cli nuget package.
The command will look something like this and can be added as a "post build" script
dotnet <nugetpackages>\Swashbuckle.AspNetCore.Cli\bin\$(Configuration)\netcoreapp<ver>\dotnet-swagger.dll tofile --host http://localhost --output swagger.json <bin>\<AssemblyName>.dll v1
more details can be found here https://github.com/domaindrivendev/Swashbuckle.AspNetCore#swashbuckleaspnetcorecli
I'm not sure about generating separate files for each environment offhand
The simple way is using PowerShell task to update json file and save with another name.
Simple workflow:
Read the file through Get-Content script
Using ConvertFrom-Json to converts content to object
Set the property value to update object
Using ConvertTo-Json to convert an object to a JSON-formatted string
Using Set-Content to write content to a file
For detail code, you can refer to this thread: how do I update json file using powershell.
The build number value is stored in the predefined variable: Build.BuildNumber (PowerShell: $env:BUILD_BUILDNUMBER)