Skip to content

Commit 6a800e5

Browse files
committed
Update README and GitHub client to change repository description updates to homepage URL updates in one-entry mode. Add tests for the new homepage update functionality.
1 parent a3b8a8c commit 6a800e5

File tree

4 files changed

+85
-24
lines changed

4 files changed

+85
-24
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A GitHub Action that automatically converts markdown files in your repository to
1212
- 📋 Maintains a mapping file of all created pages
1313
- ⚙️ Configurable file patterns for inclusion/exclusion
1414
- 🎯 Uses existing Telegraph account or creates a new one
15-
- 🔀 **One Entry Mode**: Automatically updates repository description with Telegraph URL when only one page is created
15+
- 🔀 **One Entry Mode**: Automatically updates repository homepage URL with Telegraph URL when only one page is created
1616
- 🔄 **Page Replacement**: Reuse existing Telegraph pages instead of creating new ones (maintains same URLs)
1717

1818
## Usage
@@ -88,17 +88,17 @@ jobs:
8888
8989
## Inputs
9090
91-
| Input | Description | Required | Default |
92-
| ------------------------ | ----------------------------------------------------------- | -------- | ------------------------ |
93-
| `account-name` | Telegraph account short name | No | `'GitHub Action'` |
94-
| `author-name` | Author name for Telegraph pages | No | `'GitHub Action'` |
95-
| `author-url` | Author URL for Telegraph pages | No | - |
96-
| `include-patterns` | Comma-separated glob patterns for files to include | No | `'**/*.md'` |
97-
| `exclude-patterns` | Comma-separated glob patterns for files to exclude | No | `'node_modules/**'` |
98-
| `output-file` | Output file to store page mappings | No | `'telegraph-pages.json'` |
99-
| `telegraph-token` | Existing Telegraph access token | No | - |
100-
| `one-entry-mode` | Update repository description when only one page is created | No | `'false'` |
101-
| `replace-existing-pages` | Reuse existing Telegraph pages instead of creating new ones | No | `'false'` |
91+
| Input | Description | Required | Default |
92+
| ------------------------ | ------------------------------------------------------------ | -------- | ------------------------ |
93+
| `account-name` | Telegraph account short name | No | `'GitHub Action'` |
94+
| `author-name` | Author name for Telegraph pages | No | `'GitHub Action'` |
95+
| `author-url` | Author URL for Telegraph pages | No | - |
96+
| `include-patterns` | Comma-separated glob patterns for files to include | No | `'**/*.md'` |
97+
| `exclude-patterns` | Comma-separated glob patterns for files to exclude | No | `'node_modules/**'` |
98+
| `output-file` | Output file to store page mappings | No | `'telegraph-pages.json'` |
99+
| `telegraph-token` | Existing Telegraph access token | No | - |
100+
| `one-entry-mode` | Update repository homepage URL when only one page is created | No | `'false'` |
101+
| `replace-existing-pages` | Reuse existing Telegraph pages instead of creating new ones | No | `'false'` |
102102

103103
## Outputs
104104

@@ -109,13 +109,13 @@ jobs:
109109

110110
## One Entry Mode
111111

112-
When enabled with `one-entry-mode: "true"`, this feature automatically updates your repository description with the Telegraph URL when exactly one markdown file is processed. This is perfect for single-page documentation repositories, personal profiles, or project showcases.
112+
When enabled with `one-entry-mode: "true"`, this feature automatically updates your repository homepage URL with the Telegraph URL when exactly one markdown file is processed. This is perfect for single-page documentation repositories, personal profiles, or project showcases.
113113
114114
### How One Entry Mode Works
115115
116116
1. **Enable the feature**: Set `one-entry-mode: "true"` in your workflow
117117
2. **Single page detection**: When exactly one markdown file is processed, the action detects this scenario
118-
3. **Repository update**: The GitHub repository description is automatically updated with the Telegraph page URL
118+
3. **Repository update**: The GitHub repository homepage URL is automatically updated with the Telegraph page URL
119119
4. **Permission handling**: Gracefully handles cases where the GitHub token lacks repository write permissions
120120

121121
### One Entry Mode Example
@@ -140,11 +140,11 @@ When enabled with `one-entry-mode: "true"`, this feature automatically updates y
140140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141141
```
142142

143-
**Result**: If only `README.md` is processed, your repository description will be automatically updated to point to the Telegraph page (e.g., `https://telegra.ph/My-Profile-12-15`).
143+
**Result**: If only `README.md` is processed, your repository homepage URL will be automatically updated to point to the Telegraph page (e.g., `https://telegra.ph/My-Profile-12-15`).
144144

145145
### One Entry Mode Requirements
146146

147-
- **GITHUB_TOKEN**: Must be provided via `env` for repository description updates
147+
- **GITHUB_TOKEN**: Must be provided via `env` for repository homepage updates
148148
- The GitHub token must have `metadata: write` or `contents: write` permissions
149149
- If permissions are insufficient, the action will show a warning but continue successfully
150150
- Only works when exactly one markdown file is processed

src/__tests__/github-client.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,47 @@ describe("GitHubClient", () => {
185185
});
186186
});
187187

188+
describe("updateRepositoryHomepage", () => {
189+
beforeEach(() => {
190+
client = new GitHubClient();
191+
});
192+
193+
it("should update repository homepage URL successfully", async () => {
194+
const homepageUrl = "https://telegra.ph/My-Page-123";
195+
196+
mockOctokit.rest.repos.update.mockResolvedValue({});
197+
198+
await client.updateRepositoryHomepage(homepageUrl);
199+
200+
expect(mockOctokit.rest.repos.update).toHaveBeenCalledWith({
201+
owner: "test-owner",
202+
repo: "test-repo",
203+
homepage: homepageUrl,
204+
});
205+
206+
expect(core.info).toHaveBeenCalledWith(
207+
`Updating repository homepage URL to: ${homepageUrl}`
208+
);
209+
expect(core.info).toHaveBeenCalledWith(
210+
"✅ Repository homepage URL updated successfully"
211+
);
212+
});
213+
214+
it("should handle update errors", async () => {
215+
const homepageUrl = "https://telegra.ph/My-Page-123";
216+
const error = new Error("Insufficient permissions");
217+
218+
mockOctokit.rest.repos.update.mockRejectedValue(error);
219+
220+
await expect(
221+
client.updateRepositoryHomepage(homepageUrl)
222+
).rejects.toThrow("Insufficient permissions");
223+
expect(core.error).toHaveBeenCalledWith(
224+
"Failed to update repository homepage URL: Error: Insufficient permissions"
225+
);
226+
});
227+
});
228+
188229
describe("checkPermissions", () => {
189230
beforeEach(() => {
190231
client = new GitHubClient();

src/github-client.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ export class GitHubClient {
7777
}
7878
}
7979

80+
/**
81+
* Update repository homepage URL
82+
*/
83+
async updateRepositoryHomepage(homepageUrl: string): Promise<void> {
84+
try {
85+
const { owner, repo } = this.getCurrentRepository();
86+
87+
core.info(`Updating repository homepage URL to: ${homepageUrl}`);
88+
89+
await this.octokit.rest.repos.update({
90+
owner,
91+
repo,
92+
homepage: homepageUrl,
93+
});
94+
95+
core.info(`✅ Repository homepage URL updated successfully`);
96+
} catch (error) {
97+
core.error(`Failed to update repository homepage URL: ${error}`);
98+
throw error;
99+
}
100+
}
101+
80102
/**
81103
* Check if the current GitHub token has the necessary permissions
82104
*/

src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,32 @@ export async function run(): Promise<void> {
186186
if (config.oneEntryMode && newMappings.length === 1) {
187187
try {
188188
core.info(
189-
"One entry mode enabled and exactly one page created. Updating repository description..."
189+
"One entry mode enabled and exactly one page created. Updating repository homepage URL..."
190190
);
191191

192192
const githubClient = new GitHubClient();
193193
const hasPermissions = await githubClient.checkPermissions();
194194

195195
if (hasPermissions) {
196196
const singlePage = newMappings[0];
197-
await githubClient.updateRepositoryDescription(
198-
singlePage.telegraphUrl
199-
);
197+
await githubClient.updateRepositoryHomepage(singlePage.telegraphUrl);
200198
core.info(
201-
`✅ Repository description updated with Telegraph URL: ${singlePage.telegraphUrl}`
199+
`✅ Repository homepage URL updated with Telegraph URL: ${singlePage.telegraphUrl}`
202200
);
203201
} else {
204202
core.warning(
205-
"GitHub token does not have sufficient permissions to update repository description. Please ensure the token has 'metadata: write' or 'contents: write' permissions."
203+
"GitHub token does not have sufficient permissions to update repository homepage URL. Please ensure the token has 'metadata: write' or 'contents: write' permissions."
206204
);
207205
}
208206
} catch (error) {
209207
core.warning(
210-
`Failed to update repository description in one entry mode: ${error}`
208+
`Failed to update repository homepage URL in one entry mode: ${error}`
211209
);
212210
// Don't fail the entire action for this feature
213211
}
214212
} else if (config.oneEntryMode && newMappings.length !== 1) {
215213
core.info(
216-
`One entry mode enabled but ${newMappings.length} pages were created. Repository description will not be updated.`
214+
`One entry mode enabled but ${newMappings.length} pages were created. Repository homepage URL will not be updated.`
217215
);
218216
}
219217

0 commit comments

Comments
 (0)