aws-samples / aws-samples/sample-autonomous-cloud-coding-agents

fix(slack): pasted GitHub URL in a mention resolves to the wrong repo (github.com/<owner>)

Aperta
#850 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
143
Fork
46
Merge medio
3g 10h
PR unite (30g)
24

Descrizione

## Summary

Mentioning the Slack bot with a pasted GitHub URL extracts the wrong repo. The
mention repo pattern treats `github.com` as the owner segment, so
`https://github.com/aws-samples/sample-interview-assistant-serverless/issues/24`
resolves to the repo `github.com/aws-samples` and the task is rejected with
`Repository 'github.com/aws-samples' is not onboarded`.

Pasting a URL is the natural thing to do in Slack — Slack linkifies and unfurls
it automatically — so this affects effectively every new user.

## Reproduction

In a channel where the bot is installed:

```
@bot fix https://github.com/aws-samples/sample-interview-assistant-serverless/issues/24
```

Observed: :x: reaction and reply
`Failed to create task: Repository 'github.com/aws-samples' is not onboarded. Register it with a Blueprint before submitting tasks.`

Expected: task created against `aws-samples/sample-interview-assistant-serverless`, issue 24.

## Root cause

`cdk/src/handlers/slack-events.ts:185`:

```ts
const repoPattern = /\b([a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+(?:#\d+)?)\b/;
```

`.` is inside the owner character class, so `github.com` is a valid owner match
and the pattern matches the leftmost `/` pair.

Verified against the exact inbound text (after `<@Uxxx>` stripping):

| Input | Extracted |
|---|---|
| `fix ` | `github.com/aws-samples` |
| `fix https://github.com/aws-samples/sample-interview-assistant-serverless/issues/24` | `github.com/aws-samples` |
| `fix aws-samples/sample-interview-assistant-serverless#24` | `aws-samples/sample-interview-assistant-serverless#24` |

Two aggravating factors:

1. The bad value passes `isValidRepo` (`cdk/src/handlers/shared/validation.ts:45`),
which also permits dots in the owner segment — so it reaches the onboarding
check rather than failing validation with a clearer message.
2. A URL match pre-empts the channel default repo
(`bgagent slack onboard-channel`), because `handleSubmit` only falls back to
the default when no repo token matched
(`cdk/src/handlers/slack-command-processor.ts:207-217`). So an onboarded
channel does not work around it.

## Proposed fix

In `slack-events.ts`, before the bare `owner/repo` match:

1. Normalize GitHub URLs to `owner/repo#N` — recognize
`https://github.com//` optionally followed by
`/issues/` or `/pull/`, and strip Slack's `<...>` / `` wrapper.
2. Require the matched URL host to be `github.com` / `www.github.com`.
3. Exclude host-like owners from the bare pattern so a stray `example.com/foo`
cannot be mistaken for a repo.

## Acceptance criteria

- [ ] Pasted issue URL, PR URL, and bare repo URL all resolve to `owner/repo`, with the issue/PR number carried through
- [ ] Slack's `` and `` wrappers handled
- [ ] Non-GitHub URLs do not produce a repo match; the channel default applies instead
- [ ] Existing `owner/repo#N` short form keeps working
- [ ] Unit tests in `cdk/test/` cover each row of the table above

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalla logica di estrazione del repository in cdk/src/handlers/slack-events.ts:185, quindi esamina validation.ts:45 e il flusso di fallback in cdk/src/handlers/slack-command-processor.ts:207-217. Esegui o estendi gli unit test in cdk/test/ per gli input URL e in forma breve elencati. Il lavoro è completato quando i casi GitHub issue, pull-request, bare-repository, Slack-wrapped, non-GitHub e channel-default vengono risolti come specificato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, backend, testing
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
78/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.