# Discovery rules

> Choose which repositories a source adds with discovery rules, preview them, index new ones automatically and read why a listed repository was not added.

Source: https://docs.corfedo.ai/workspace/sources/discovery-rules/

A discovery rule chooses which repositories a source adds to the workspace. Discovery never grants access to code. Who can read a repository is set by its [access](https://docs.corfedo.ai/workspace/sources/repositories/#who-can-read-a-repository).

## Before you begin

- You are a workspace administrator or have the **Repository administrator** role.
- A source that shows **Healthy**, from [Sources](https://docs.corfedo.ai/workspace/sources/).

## Add a rule

### Open the rules

Open **Settings** › **Sources**, open the connection and select the **Rules** tab. Select **Add rule** and enter a **Name**.

### Choose what the rule selects

| **Selects** | Use it for |
| --- | --- |
| **All repositories the credential can access** | Everything the token or app can read |
| **Repositories of one owner** | One organization, group or account. Public repositories the credential can read are included. |
| **A list of repositories** | Up to 1,000 named repositories, one per line, as a name such as `acme/billing` or a link on the forge |

For the first two, **Include** and **Exclude** narrow the selection with up to 20 patterns each, matched against the whole name. `*` matches any characters including `/`, and `?` matches one character. For example, include `acme/api-*` and exclude `*-archive`. Select **Preview** to see the first matches before you save.

### Choose how new repositories are indexed

- **Include archived repositories** adds archived ones too.
- **Index new repositories automatically** indexes the repositories the rule adds. Without it, each one waits for **Index now** on its page. Repositories already indexed stay up to date either way.

Select **Add rule**.

### Run it

Saving a rule does not run it. Select **Run now** on the rule, or **Run discovery** on the connection for every enabled rule.

**Check:** the rule's **Activity** shows the run, and the connection's **Repositories** tab lists the repositories it added.

## When discovery runs

Each connection runs discovery on a schedule, set under **Settings** › **Find new repositories** on the connection: **Every hour**, **Every 6 hours**, **Every day** or **Manual only**. **Check for changes**, on the same tab, has its own schedule and indexes new commits of the connection's repositories.

A rule that is not **Enabled** keeps its repositories but adds no new ones. **Delete rule** removes the rule with its runs. Repositories it added stay in the workspace. Narrowing a rule does not remove repositories either. The rule's **Activity** lists them as no longer matched. Delete them from their page if you no longer want them.

## Read a list rule's results

A list rule shows each repository's outcome from the latest run. **Needs review** shows only the problems.

| Outcome | Why | What to do |
| --- | --- | --- |
| **Added** or **Already present** | The repository is linked | Nothing |
| **Not found** | The forge has no repository with this name | Check the spelling, or whether it was renamed |
| **No access** | The credential cannot read it | Give the token or app access on the forge, then run the rule again |
| **Excluded** | The forge has it, but the rule does not take it, for example because it is archived | Select **Include archived repositories** if it is archived |
| **Check failed** | The forge's answer could not be read | Run the rule again later |

## Related

- [Repositories](https://docs.corfedo.ai/workspace/sources/repositories/) covers indexing settings, statuses and removal.
