Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: React migration - Repository Integrations CY-6642 #2007

Merged
merged 53 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7b8bff3
wip: Add TODOs
Jan 16, 2024
b00bc81
feat: Replace project token by repository token
Jan 17, 2024
8d06c2a
feat: Update repository token procedure steps
Jan 17, 2024
3286d4f
feat: Replace project token by repository token in the API examples
Jan 17, 2024
d5f9b1d
clean: Rename API examples filename for consistency
Jan 17, 2024
5db7dc0
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Jan 17, 2024
a2fd91a
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Jan 18, 2024
27dbbe5
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Jan 22, 2024
dbb4c42
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Jan 23, 2024
c840bfc
wip: Signalize screenshots to update and add TODOS for git provider i…
Jan 24, 2024
c5cdf48
feat: Update post-commit hooks content; remove unused images
Jan 24, 2024
ad7a185
fix: Move TODOs impacting section id
Jan 24, 2024
15b304d
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Jan 25, 2024
19eb800
feat: Add temporary repo token screenshot; update account token scree…
Jan 25, 2024
501812b
clean: Delete unused screenshot
Jan 25, 2024
53ce494
feat: Rename project API tokens section ID and corresponding references
Jan 25, 2024
89bfb68
clean: Remove TODOs related to project API token renaming
Jan 25, 2024
8ca4b7f
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Feb 21, 2024
7100980
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Feb 29, 2024
f6e3c87
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Mar 11, 2024
38e9e06
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Mar 13, 2024
13c3769
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Mar 14, 2024
ee836bc
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Mar 21, 2024
be53a54
Merge branch 'master' into CY-6642-repository-integrations-migration
nicklem Apr 4, 2024
00953b2
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Apr 10, 2024
badcee1
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Apr 16, 2024
93c94a6
feat: Remove enabling concept from GitHub integration
Apr 17, 2024
fb8e099
feat: Add section to refresh integration and corresponding admonition
Apr 17, 2024
a3e5d21
feat: Add temporary screenshot for refresh integration
Apr 17, 2024
becd75f
feat: Replace enabling by refreshing concept on GitLab integration
Apr 17, 2024
5595364
fix: Fix broken link and small tweaks
Apr 17, 2024
48cd6fb
feat: Replace enabling by refreshing concept on Bitbucket integration
Apr 17, 2024
a611744
fix: Fix typos
Apr 17, 2024
4d9ddd7
feat: Remove the enable integration concept from the getting started …
Apr 17, 2024
35be2af
feat: Remove integration refresh from the procedure to use a dedicate…
Apr 17, 2024
4c19e8a
feat: Remove admonition for new repositories which no longer applies
Apr 17, 2024
42e595c
feat: Replace re-enable with refresh
Apr 17, 2024
bafbc1c
feat: Replace remove and re-create with refresh integration
Apr 17, 2024
3b500da
feat: Move service account admonition to refresh section
Apr 17, 2024
2afe1d6
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Apr 26, 2024
ce152b0
feat: Refresh integration doesn't apply to GitHub
Apr 26, 2024
8ad348c
feat: Align refresh button copy with UI
Apr 26, 2024
1eace77
clean: Highlight service account tip and link to specific section
Apr 26, 2024
ba69752
clean: Link to new integration refresh section instead
Apr 26, 2024
58167a1
feat: Update repository token screenshot; formatting tweak
Apr 26, 2024
3aa47f2
feat: Update post-commit hook screenshot
Apr 26, 2024
102b768
wip: Remove renaming TODO
Apr 26, 2024
90fad27
feat: Update GitHub integration screenshot
Apr 26, 2024
810e6de
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro Apr 29, 2024
3edb943
feat: Update GitLab option names and screenshots
Apr 29, 2024
b7faefd
fix: Keep previous section IDs to prevent broken links
Apr 29, 2024
e944041
feat: Update option names and screenshots for Bitbucket interation
Apr 29, 2024
660f864
Merge branch 'master' into CY-6642-repository-integrations-migration
claudiacarpinteiro May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
Loading