Skip to content

Commit

Permalink
feat: React migration - Repository Integrations CY-6642 (#2007)
Browse files Browse the repository at this point in the history
* wip: Add TODOs

* feat: Replace project token by repository token

* feat: Update repository token procedure steps

* feat: Replace project token by repository token in the API examples

* clean: Rename API examples filename for consistency

* wip: Signalize screenshots to update and add TODOS for git provider integrations

* feat: Update post-commit hooks content; remove unused images

* fix: Move TODOs impacting section id

* feat: Add temporary repo token screenshot; update account token screenshot

* clean: Delete unused screenshot

* feat: Rename project API tokens section ID and corresponding references

* clean: Remove TODOs related to project API token renaming

* feat: Remove enabling concept from GitHub integration

* feat: Add section to refresh integration and corresponding admonition

* feat: Add temporary screenshot for refresh integration

* feat: Replace enabling by refreshing concept on GitLab integration

* fix: Fix broken link and small tweaks

* feat: Replace enabling by refreshing concept on Bitbucket integration

* fix: Fix typos

* feat: Remove the enable integration concept from the getting started path

* feat: Remove integration refresh from the procedure to use a dedicated service account

* feat: Remove admonition for new repositories which no longer applies

* feat: Replace re-enable with refresh

* feat: Replace remove and re-create with refresh integration

* feat: Move service account admonition to refresh section

* feat: Refresh integration doesn't apply to GitHub

* feat: Align refresh button copy with UI

* clean: Highlight service account tip and link to specific section

* clean: Link to new integration refresh section instead

* feat: Update repository token screenshot; formatting tweak

* feat: Update post-commit hook screenshot

* wip: Remove renaming TODO

* feat: Update GitHub integration screenshot

* feat: Update GitLab option names and screenshots

* fix: Keep previous section IDs to prevent broken links

* feat: Update option names and screenshots for Bitbucket interation

---------

Co-authored-by: Nicola Klemenc <[email protected]>
  • Loading branch information
claudiacarpinteiro and nicklem authored May 8, 2024
1 parent ae143a3 commit 887f389
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 143 deletions.
4 changes: 2 additions & 2 deletions docs/assets/includes/client-side-tool-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

1. Set up an API token to authenticate on Codacy:

- **If you're setting up one repository**, [obtain a project API token](../../codacy-api/api-tokens.md#project-api-tokens) and set the following environment variable to specify your project API token:
- **If you're setting up one repository**, [obtain a repository API token](../../codacy-api/api-tokens.md#repository-api-tokens) and set the following environment variable to specify your repository API token:

```bash
export CODACY_PROJECT_TOKEN=<your project API token>
export CODACY_PROJECT_TOKEN=<your repository API token>
```

- **If you're setting up multiple repositories**, [obtain an account API Token](../../codacy-api/api-tokens.md#account-api-tokens) and set the following environment variable to specify the account API token:
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/includes/service-account-integration.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!!! tip
Use a dedicated service account to integrate Codacy with your repositories. This prevents disruption of service if the user who originally enabled the integration loses access to the repositories, which may happen when a user leaves the team or the organization.

For more information and instructions on how to set up a dedicated service account see [Why did Codacy stop commenting on pull requests?](../../faq/troubleshooting/why-did-codacy-stop-commenting-on-pull-requests.md)
For more information and instructions on how to set up a dedicated service account see [Why did Codacy stop commenting on pull requests?](../../faq/troubleshooting/why-did-codacy-stop-commenting-on-pull-requests.md#outdated-permissions)
24 changes: 11 additions & 13 deletions docs/codacy-api/api-tokens.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
description: Create an account API token to authorize access to all the repositories that you have access to, or a project API token to authorize access only to a specific repository.
description: Create an account API token to authorize access to all the repositories that you have access to, or a repository API token to authorize access only to a specific repository.
---

# API tokens

Codacy provides **account** and **project**-level API tokens that allow you to:
Codacy provides **account** and **repository**-level API tokens that allow you to:

- [Upload coverage data](../coverage-reporter/index.md) to Codacy
- Upload to Codacy the results of [running client-side analysis tools](../repositories-configure/local-analysis/client-side-tools.md)
Expand All @@ -23,7 +23,7 @@ Account API tokens are defined at the **Codacy user account level**. Each accoun

Use a dedicated service account to integrate Codacy with your repositories. This prevents disruption of service if the user who created an account API token loses access to the repositories, which may happen when a user leaves the team or the organization.

You can create new account API tokens programmatically [using the Codacy API](examples/creating-project-api-tokens-programmatically.md) or using the Codacy UI:
You can create new account API tokens programmatically [using the Codacy API](examples/creating-repository-api-tokens-programmatically.md) or using the Codacy UI:

1. Open your account, tab **Access management**.

Expand All @@ -36,27 +36,25 @@ You can create new account API tokens programmatically [using the Codacy API](ex

To revoke an account API token, click the "X" next to the token. After this, all applications or services using that token to access the Codacy API will fail to authenticate and will receive the reply `{"error":"not found"}`.

## Generating and revoking project API tokens {: id="project-api-tokens"}
## Generating and revoking repository API tokens {: id="repository-api-tokens"}

Project API tokens are defined on **individual repositories**. Each project API token only authorizes access to the corresponding repository.
Repository API tokens are defined on **individual repositories**. Each repository API token only authorizes access to the corresponding repository.

You can create new project API tokens programmatically [using the Codacy API](examples/creating-project-api-tokens-programmatically.md) or using the Codacy UI:
You can create new repository API tokens programmatically [using the Codacy API](examples/creating-repository-api-tokens-programmatically.md) or using the Codacy UI:

1. Open your repository **Settings**, tab **Integrations**.

1. Click the button **Add integration** and add a **Project API** integration.

1. Click the button **Settings** on the **Project API** integration and copy the project API token.
1. Click the button **Create API token** under **Repository API tokens**.

!!! tip
You can create multiple (up to 100) project API tokens per repository. This can be useful to have a more flexible control by revoking only a specific token.
You can create multiple (up to 100) API tokens per repository. This can be useful to have a more flexible control by revoking only a specific token.

![Creating a project API token](images/codacy-api-tokens-project.png)
![Creating a repository API token](images/codacy-api-tokens-repository.png)

To revoke a project API token, click the trash can icon for the corresponding **Project API** integration. After this, all applications or services using that token to access the Codacy API will fail to authenticate and will receive the reply `{"error":"not found"}`.
To revoke a repository API token, click the **X** next to the token. After this, all applications or services using that token to access the Codacy API will fail to authenticate and will receive the reply `{"error":"not found"}`.

## See also

- [Adding coverage to your repository](../coverage-reporter/index.md)
- [Client-side tools](../repositories-configure/local-analysis/client-side-tools.md)
- [Creating project API tokens programmatically](examples/creating-project-api-tokens-programmatically.md)
- [Creating repository API tokens programmatically](examples/creating-repository-api-tokens-programmatically.md)
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
description: Example of how to create new project API tokens for all repositories in an organization using the Codacy API endpoint createRepositoryApiToken.
description: Example of how to create new repository API tokens for all repositories in an organization using the Codacy API endpoint createRepositoryApiToken.
---


# Creating project API tokens programmatically
# Creating repository API tokens programmatically

To create new [project API tokens](../api-tokens.md) for your Codacy repositories programmatically, use the Codacy API endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken). You can also list all project API tokens for a repository using the endpoint [listRepositoryApiTokens](https://api.codacy.com/api/api-docs#listrepositoryapitokens).
To create new [repository API tokens](../api-tokens.md) for your Codacy repositories programmatically, use the Codacy API endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken). You can also list all repository API tokens for a repository using the endpoint [listRepositoryApiTokens](https://api.codacy.com/api/api-docs#listrepositoryapitokens).

For example, if you're [setting up coverage](../../coverage-reporter/index.md) for all your repositories and prefer not to use a single account API token that grants the same permissions as an administrator, you need to create an individual project API token for each repository.
For example, if you're [setting up coverage](../../coverage-reporter/index.md) for all your repositories and prefer not to use a single account API token that grants the same permissions as an administrator, you need to create an individual repository API token for each repository.

## Example: Creating a project API token for a single repository
## Example: Creating a repository API token for a single repository

This example creates a new project API token for a repository and outputs the new token string.
This example creates a new repository API token for a repository and outputs the new token string.

The example script:

1. Defines the [account API token](../api-tokens.md#account-api-tokens) used to authenticate on the Codacy API, the Git provider, the organization name, and the repository name passed as an argument to the script.
1. Calls the endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken) to create a new project API token and uses [jq](https://github.com/stedolan/jq) to obtain only the created token string.
1. Calls the endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken) to create a new repository API token and uses [jq](https://github.com/stedolan/jq) to obtain only the created token string.

```bash
#!/bin/bash
Expand All @@ -35,20 +35,20 @@ Example usage and output

```bash
$ ./create-token.sh website
<new project API token>
<new repository API token>
```

## Example: Creating project API tokens for all repositories in an organization
## Example: Creating repository API tokens for all repositories in an organization

This example creates new project API tokens for all the repositories in an organization and outputs a comma-separated list of repository names and corresponding token strings.
This example creates new repository API tokens for all the repositories in an organization and outputs a comma-separated list of repository names and corresponding token strings.

The example script:

1. Defines the [account API token](../api-tokens.md#account-api-tokens) used to authenticate on the Codacy API, the Git provider, and the organization name.
1. Calls the endpoint [listOrganizationRepositories](https://api.codacy.com/api/api-docs#listorganizationrepositories) to retrieve the list of repositories in the organization.
1. Uses [jq](https://github.com/stedolan/jq) to select only the name of the repositories.
1. Asks for confirmation from the user before making any changes.
1. For each repository, calls the endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken) to create a new project API token and uses jq to obtain only the created token string.
1. For each repository, calls the endpoint [createRepositoryApiToken](https://app.codacy.com/api/api-docs#createrepositoryapitoken) to create a new repository API token and uses jq to obtain only the created token string.
1. Outputs a comma-separated list of the repository names and the corresponding new token strings.
1. Pauses a few seconds between requests to the Codacy API to avoid rate limiting.

Expand All @@ -64,7 +64,7 @@ repositories=$(curl -sX GET "https://app.codacy.com/api/v3/organizations/$GIT_PR
| jq -r ".data[] | .name")

count=$(echo "$repositories" | wc -l)
read -p "Create project tokens for $count repositories? (y/n) " choice
read -p "Create repository tokens for $count repositories? (y/n) " choice
if [ "$choice" = "y" ]; then
echo "$repositories" | while read repository; do
echo -n "$repository,"
Expand All @@ -81,22 +81,22 @@ fi
Example output:

```text
chart,<new project API token>
docs,<new project API token>
website,<new project API token>
chart,<new repository API token>
docs,<new repository API token>
website,<new repository API token>
[...]
```

{% include-markdown "../../assets/includes/api-example-pagination-important.md" %}

## Example: Listing the project API tokens for a repository
## Example: Listing the repository API tokens for a repository

This example lists all project API tokens created for a repository.
This example lists all repository API tokens created for a repository.

The example script:

1. Defines the [account API token](../api-tokens.md#account-api-tokens) used to authenticate on the Codacy API, the Git provider, the organization name, and the repository name passed as an argument to the script.
1. Calls the endpoint [listRepositoryApiTokens](https://api.codacy.com/api/api-docs#listrepositoryapitokens) to list the project API tokens available on the repository and uses [jq](https://github.com/stedolan/jq) to obtain only the token strings, or exit with a non-zero status if the repository doesn't have any project API tokens created yet.
1. Calls the endpoint [listRepositoryApiTokens](https://api.codacy.com/api/api-docs#listrepositoryapitokens) to list the repository API tokens available on the repository and uses [jq](https://github.com/stedolan/jq) to obtain only the token strings, or exit with a non-zero status if the repository doesn't have any repository API tokens created yet.

```bash
#!/bin/bash
Expand All @@ -110,11 +110,11 @@ curl -sX GET "https://app.codacy.com/api/v3/organizations/$GIT_PROVIDER/$ORGANIZ
| jq -er ".data[] | .token"
```

Example usage to obtain only the project API token created most recently for the repository:
Example usage to obtain only the repository API token created most recently for the repository:

```bash
$ ./list-tokens.sh website | head -n 1
<last project API token created>
<last repository API token created>
```

## See also
Expand Down
Binary file modified docs/codacy-api/images/codacy-api-tokens-account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/codacy-api/images/codacy-api-tokens-project.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/codacy-api/using-the-codacy-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Codacy supports two API versions but we strongly recommend using the new API v3

## Authenticating requests

Most API endpoints require that you authenticate using an API token. After [obtaining the necessary tokens](api-tokens.md), include them in your request headers using the format `api-token: <your account API token>` or `project-token: <your project API token>`.
Most API endpoints require that you authenticate using an API token. After [obtaining the necessary tokens](api-tokens.md), include them in your request headers using the format `api-token: <your account API token>` or `project-token: <your repository API token>`.

!!! note
Currently, all API v3 endpoints that require authentication must use **account API tokens**, while the API v2 endpoints require either **account or project API tokens**.
Currently, all API v3 endpoints that require authentication must use **account API tokens**, while the API v2 endpoints require either **account or repository API tokens**.

Performing `GET` requests for public repositories doesn't require authentication.

Expand All @@ -83,11 +83,11 @@ curl -X GET 'https://api.codacy.com/api/v3/user/organizations/gh' \
-H 'api-token: <your account API token>'
```

Or to make a request to an API v2 endpoint that requires a project API token:
Or to make a request to an API v2 endpoint that requires a repository API token:

```bash
curl -X GET 'https://api.codacy.com/2.0/commit/da275c14ffab6e402dcc6009828067ffa44b7ee0' \
-H 'project-token: <your project API token>'
-H 'project-token: <your repository API token>'
```

## Using parameters in requests
Expand Down
6 changes: 3 additions & 3 deletions docs/coverage-reporter/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ After having coverage reports set up for your repository, you must use the Codac
1. Set up an API token to allow Codacy Coverage Reporter to authenticate on Codacy:
{: id="authenticate"}

- **If you're setting up coverage for one repository**, [obtain a project API token](../codacy-api/api-tokens/#project-api-tokens) and set the following environment variable to specify your project API token:
- **If you're setting up coverage for one repository**, [obtain a repository API token](../codacy-api/api-tokens.md#repository-api-tokens) and set the following environment variable to specify your repository API token:
```bash
export CODACY_PROJECT_TOKEN=<your project API token>
export CODACY_PROJECT_TOKEN=<your repository API token>
```
- **If you're setting up and automating coverage for multiple repositories**, [obtain an account API Token](../codacy-api/api-tokens/#account-api-tokens) and set the following environment variables:
- **If you're setting up and automating coverage for multiple repositories**, [obtain an account API Token](../codacy-api/api-tokens.md#account-api-tokens) and set the following environment variables:

- **CODACY_API_TOKEN:** Your account API token.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ If the user that initially configured the repository on Codacy was using a user

![Generate new key](images/we-no-longer-have-access-to-this-repository-new-key.png)

1. Open the tab **Integrations**. If you have an integration with your Git provider enabled, [remove and re-create the integration](why-did-codacy-stop-commenting-on-pull-requests.md).
1. Open the tab **Integrations**, and refresh your [GitLab](../../repositories-configure/integrations/gitlab-integration.md#refreshing) or [Bitbucket](../../repositories-configure/integrations/bitbucket-integration.md#refreshing) integration.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Coverage information is currently sent to GitHub by a new version of the Codacy

If you stopped receiving coverage summaries on your pull requests, please [review and accept the updated Codacy app permissions on GitHub](https://docs.github.com/en/enterprise-cloud@latest/apps/using-github-apps/reviewing-and-modifying-installed-github-apps#reviewing-permissions). For more information on the rollout of the new Coverage engine, [see the relevant release note](../../release-notes/cloud/cloud-2023-11-23-new-coverage-engine-status-checks.md).

## Outdated permissions or invalid SSH key
## Outdated permissions or invalid SSH key {: id="outdated-permissions"}

!!! info "This section applies to GitLab and Bitbucket"

Different reasons can cause Codacy to stop analyzing and commenting on pull requests, but the most common is that the user who initially enabled the GitLab or Bitbucket integration no longer has permissions on the repository or that the SSH key is no longer valid.

To fix this issue and avoid future disruptions, re-enable the GitLab or Bitbucket integration on Codacy using a dedicated service account on your Git provider:
To fix this issue and avoid future disruptions, refresh the GitLab or Bitbucket integration on Codacy using a dedicated service account on your Git provider:

1. Create a service account on your Git provider exclusively dedicated to integrating Codacy with your repositories.

Expand All @@ -33,21 +33,15 @@ To fix this issue and avoid future disruptions, re-enable the GitLab or Bitbucke

1. Log in to Codacy using the new service account.

1. Open your repository **Settings**, tab **Integrations**, and click the trash can icon to remove the existing Git provider integration:
1. Open your repository **Settings**, tab **Integrations**, and click the link **Refresh connection** to refresh the existing Git provider integration:

![Removing the old Git provider integration](images/git-provider-integration-remove.png)
![Refresh Git provider integration](../../repositories-configure/integrations/images/gitlab-integration-refresh.png)

1. Re-enable the integration by following the instructions for your Git provider:
1. Make sure the Git provider integration is configured as needed:

- [Enabling the GitLab integration](../../repositories-configure/integrations/gitlab-integration.md#enabling)
- [Configuring the GitLab integration](../../repositories-configure/integrations/gitlab-integration.md#configuring)

- [Enabling the Bitbucket integration](../../repositories-configure/integrations/bitbucket-integration.md#enabling)

{%
include-markdown "../../assets/includes/default-git-provider-settings-tip.md"
start="<!--default-settings-start-->"
end="<!--default-settings-end-->"
%}
- [Configuring the Bitbucket integration](../../repositories-configure/integrations/bitbucket-integration.md#configuring)

## See also

Expand Down
Loading

0 comments on commit 887f389

Please sign in to comment.