Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adc6fd9

Browse files
committed
docs: improve add-alias help text and update CLI reference documentation
1 parent 88e3f1c commit adc6fd9

3 files changed

Lines changed: 155 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ gitflow-analytics -c config.yaml --weeks 8
7575
- **📊 DORA Metrics**: Deployment frequency, lead time, change failure rate, and MTTR
7676
- **💰 Cost Tracking**: Monitor LLM API usage with detailed token and cost reporting
7777
- **📈 Weekly Trends**: Track classification pattern changes over time with proper Monday-aligned weeks
78+
- **🏷️ Non-Interactive Alias Management**: `gfa add-alias` command for scripting alias mappings — single or batch via YAML/JSON file, with `--dry-run` support
7879

7980
## 🔥 Core Capabilities
8081

docs/reference/cli-commands.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,100 @@ gitflow-analytics alias-rename -c config.yaml \
190190
- Always test with `--dry-run` first to preview changes
191191
- See [Managing Aliases Guide](../guides/managing-aliases.md#renaming-developers) for detailed usage
192192

193+
### add-alias
194+
Add alias mappings to a configuration file non-interactively. Suitable for scripting and CI pipelines where interactive prompts are not available.
195+
196+
```bash
197+
gfa add-alias -c config.yaml \
198+
--canonical "[email protected]" \
199+
--alias "[email protected]" \
200+
--alias "Dev Name" \
201+
[OPTIONS]
202+
```
203+
204+
**Required Options**:
205+
- `-c, --config PATH` - Path to YAML configuration file
206+
207+
**Mapping Options** (mutually exclusive — use one or the other):
208+
- `--canonical EMAIL` - Primary/canonical email for this developer identity; combine with one or more `--alias` flags
209+
- `--from-file PATH` - YAML or JSON file containing batch alias mappings (cannot be combined with `--canonical`)
210+
- `--alias EMAIL_OR_NAME` - Email address or display name to map to `--canonical`; repeatable
211+
212+
**Behaviour Flags**:
213+
- `--dry-run` - Show what would be changed without writing to the config file
214+
- `--apply` - Trigger identity re-resolution after updating the config
215+
216+
**Examples**:
217+
```bash
218+
# Map a personal email and display name to a canonical work email
219+
gfa add-alias -c config.yaml \
220+
--canonical "[email protected]" \
221+
--alias "[email protected]" \
222+
--alias "Alice Smith"
223+
224+
# Preview changes before writing
225+
gfa add-alias -c config.yaml \
226+
--canonical "[email protected]" \
227+
--alias "[email protected]" \
228+
--dry-run
229+
230+
# Load batch mappings from a YAML file and re-resolve identities
231+
gfa add-alias -c config.yaml \
232+
--from-file aliases.yaml \
233+
--apply
234+
235+
# Load batch mappings from a JSON file
236+
gfa add-alias -c config.yaml \
237+
--from-file aliases.json
238+
```
239+
240+
**Supported `--from-file` Formats**:
241+
242+
1. **GFA native YAML** — a config file with a `developer_aliases:` key:
243+
```yaml
244+
developer_aliases:
245+
- canonical: "[email protected]"
246+
aliases: ["[email protected]", "Alice Smith"]
247+
```
248+
249+
2. **Flat YAML list** — a list of `{canonical, aliases}` objects:
250+
```yaml
251+
- canonical: "[email protected]"
252+
aliases:
253+
254+
- Alice Smith
255+
- canonical: "[email protected]"
256+
aliases:
257+
258+
```
259+
260+
3. **JSON array** — equivalent structure in JSON:
261+
```json
262+
[
263+
{"canonical": "[email protected]", "aliases": ["[email protected]", "Alice Smith"]},
264+
{"canonical": "[email protected]", "aliases": ["[email protected]"]}
265+
]
266+
```
267+
268+
**What It Does**:
269+
1. Reads the existing `analysis.identity.manual_mappings` (or `developer_aliases`) section in the config
270+
2. Merges new aliases into the matching canonical entry, or creates a new entry if the canonical is not yet present
271+
3. Skips duplicates — existing aliases are never written twice (idempotent)
272+
4. Writes the updated config back to disk (unless `--dry-run` is specified)
273+
5. Optionally triggers identity re-resolution via `--apply`
274+
275+
**Use Cases**:
276+
- Onboarding automation: script alias setup as part of repo initialisation
277+
- CI pipelines: keep alias mappings in a separate file and apply them on deploy
278+
- Bulk imports: migrate alias lists from another tool's export format
279+
- Safe updates: use `--dry-run` to audit changes before committing them
280+
281+
**Notes**:
282+
- `--from-file` and `--canonical` are mutually exclusive; combining them is an error
283+
- The operation is idempotent: running the same command twice produces the same config
284+
- Always verify with `--dry-run` before running in unattended automation
285+
- See [Managing Aliases Guide](../guides/managing-aliases.md) for detailed identity management guidance
286+
193287
## 📊 Output Formats
194288

195289
### CSV Format (`--format csv`)

src/gitflow_analytics/cli_identity_alias_ops.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -635,39 +635,39 @@ def _load_alias_file(file_path: str) -> list[dict]:
635635
"-c",
636636
required=True,
637637
type=click.Path(exists=True),
638-
help="Config YAML path",
638+
help="Path to YAML configuration file",
639639
)
640640
@click.option(
641641
"--canonical",
642642
required=False,
643643
default=None,
644-
help="Canonical email address",
644+
help="Primary/canonical email for this developer identity",
645645
)
646646
@click.option(
647647
"--alias",
648648
"aliases",
649649
multiple=True,
650-
help="Alias email or name (repeatable)",
650+
help="Email or name to map to canonical (repeatable, e.g. --alias [email protected] --alias 'Jane Smith')",
651651
)
652652
@click.option(
653653
"--from-file",
654654
"from_file",
655655
required=False,
656656
default=None,
657657
type=click.Path(exists=True),
658-
help="YAML/JSON file with batch alias mappings",
658+
help="YAML or JSON file with batch alias mappings (see format below)",
659659
)
660660
@click.option(
661661
"--apply",
662662
is_flag=True,
663663
default=False,
664-
help="After writing config, rerun identity resolution to propagate to historical commits",
664+
help="Trigger identity re-resolution after updating config (propagates to cached data)",
665665
)
666666
@click.option(
667667
"--dry-run",
668668
is_flag=True,
669669
default=False,
670-
help="Print what would be done without making changes",
670+
help="Show what would be changed without writing to config",
671671
)
672672
def add_alias_command(
673673
config: str,
@@ -677,18 +677,66 @@ def add_alias_command(
677677
apply: bool,
678678
dry_run: bool,
679679
) -> None:
680-
"""Add known alias mappings to config non-interactively.
680+
"""Add alias mappings to config non-interactively.
681+
682+
Maps one or more alias emails/names to a canonical developer identity
683+
in analysis.identity.manual_mappings. Supports single mappings via
684+
--canonical/--alias flags, or bulk import via --from-file.
685+
686+
\b
687+
USAGE MODES:
681688
682-
Use --canonical + --alias for a single mapping, or --from-file for batch.
689+
Single mapping (--canonical + --alias):
690+
Adds or updates one developer's alias list. Multiple --alias
691+
flags may be provided to add several aliases at once.
692+
693+
Batch import (--from-file):
694+
Reads a YAML or JSON file containing multiple mappings.
695+
Mutually exclusive with --canonical.
683696
684697
\b
685-
Examples:
698+
FILE FORMATS (--from-file):
699+
700+
GFA native YAML (developer_aliases list):
701+
developer_aliases:
702+
- canonical: [email protected]
703+
aliases:
704+
705+
- "John Doe"
706+
- canonical: [email protected]
707+
aliases:
708+
709+
710+
Flat YAML list:
711+
- canonical: [email protected]
712+
aliases: [[email protected]]
686713
687-
# Single alias
688-
gfa add-alias -c config.yaml --canonical [email protected] --alias [email protected] --alias "John Doe"
714+
JSON array:
715+
[{"canonical": "[email protected]", "aliases": ["[email protected]"]}]
689716
690-
# Batch from YAML file
717+
\b
718+
EXAMPLES:
719+
720+
# Add single alias
721+
gfa add-alias -c config.yaml --canonical [email protected] --alias [email protected]
722+
723+
# Add multiple aliases at once
724+
gfa add-alias -c config.yaml --canonical [email protected] \\
725+
--alias [email protected] --alias "John Doe"
726+
727+
# Preview without writing
728+
gfa add-alias -c config.yaml --canonical [email protected] \\
729+
--alias [email protected] --dry-run
730+
731+
# Batch import from file
691732
gfa add-alias -c config.yaml --from-file aliases.yaml
733+
734+
\b
735+
NOTE:
736+
Existing canonical entries are merged (not replaced). Duplicate
737+
aliases are silently skipped. Use --dry-run to preview changes.
738+
After updating config, run 'gfa identities --apply' to propagate
739+
changes to cached data (or use --apply when that flag is wired).
692740
"""
693741
# Validate args
694742
if not from_file and not canonical:

0 commit comments

Comments
 (0)