Create project with API and integrate to GitHub repo

We are creating repo with going to Web URL: https://sonarcloud.io/projects/create
It integrates GitHub repo with sonarcloud and works fine.

Now we want to do this (create repo and integrate repo with GitHub) with help of API requests.
To create repo we are using WebApi api/projects/create.

How to integrate that repo with GitHub with WebAPI?

Our repositories are on Java, NodeJS, Go. And they are GitHub, private.

Thanks in advance!

Hi,

Can you clarify exactly what you mean by integrate that repo with GitHub please?

I mean analyze repo with AutoScan. When creating repo from sonarcloud.io/projects/create it will enable AutoScan also.

But in case of adding new project with WebAPI doesn’t starts AutoScan from GitHub repo.

So did you get this working. I’m looking at doing the same thing for new repos created in github every month.

Hi @tinomen and welcome to our Community!

Currently the supported and recommended way to create a new project is by using SonarCloud UI. We are aware of this automated scenario and maybe we will support it in the future. You can take a look into new features suggestions and add your if you want!

Looks like this undocumented API has changed. Sadly, using the UI isn’t feasible in our org. We produce 30-40 projects a month. We are investigating solutions that can be automated.

Hello, is it available now(APIs to integrate GitHub projects with sonar without using sonar UI)

Hi, all.

I found out how to add repo to SonarCloud for AutoScan via sonarcloud API. Here is example with CURL:

    curl --include \
        --request POST \
        --header "Content-Type: application/x-www-form-urlencoded" \
        -u ${SONAR_TOKEN}: \
        --data-binary "installationKeys=${GITHUB_ORG}%2F${REPO_NAME}%7C${REPO_ID}&organization=${SONAR_ORG}" \
        "https://sonarcloud.io/api/alm_integration/provision_projects"
    curl --include \
        -u ${SONAR_TOKEN}: \
        "https://sonarcloud.io/api/autoscan/eligibility?autoEnable=true&projectKey=${GITHUB_ORG}_${REPO_NAME}"
    curl --include \
        --request POST \
        --header "Content-Type: application/x-www-form-urlencoded" \
        -u ${SONAR_TOKEN}: \
        --data-binary "enable=true&projectKey=${GITHUB_ORG}_${REPO_NAME}" \
        "https://sonarcloud.io/api/autoscan/activation"

I hope this will help everyone :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.