Skip to content

Commit

Permalink
Merge pull request #3 from wtto00/dev
Browse files Browse the repository at this point in the history
feat: Sync Issue
  • Loading branch information
wtto00 authored Oct 10, 2023
2 parents ccdda98 + bcbdf46 commit 50b31f1
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 22 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [0.0.2]

### Added

- Github Issue Blog: Sync Issue

### Fixed

- fix: The top background color on the web page is causing the logo to not be displayed.

## [0.0.1]

First version.
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A vscode plugin to create blogs with issue.
## Install

- Search for `github issue blog` in the VS Code extension marketplace.
- Click on the [link](https://marketplace.visualstudio.com/items?itemName=wtto00.github-issue-blog), go to the official extension marketplace, and click on download to install.

## Configuration

Expand All @@ -20,6 +21,7 @@ If this configuration is not set, when executing the command, it will prompt the

- Github Issue Blog: Create Issue
- Github Issue Blog: Update Issue
- Github Issue Blog: Sync Issue

1. Global command

Expand Down Expand Up @@ -59,6 +61,6 @@ issue_number: 24
| labels | string[] | Labels of issue |
| issue_number | number | Number of issue |

- `title` is necessary.
- `labels` are not mandatory, they will be automatically created if they do not exist.
- `issue_number` is required when updating an issue. When creating an issue, the `issue_number` will be automatically updated to the number of the issue that is created.
- `title` is required when updating and creating an issue.
- `labels` are not mandatory, they will be automatically created if they do not exist when updating and creating an issue.
- `issue_number` is required when updating and synchronizing an issue. When creating an issue, the `issue_number` will be automatically updated to the number of the issue that is created.
9 changes: 6 additions & 3 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
"requestAuth": "Request Github authorization",
"unauthorized": "Unauthorized access",
"getRepository": "Get blog repository",
"createIssue": "Create issue",
"createIssue": "Creating issue",
"createSuccess": "Issue creation successful",
"viewInBrowser": "View in browser",
"updateIssue": "Update issue",
"updateIssue": "Updating issue",
"updateSuccess": "Updated Issue successfully",
"syncIssue": "Syncing issue",
"syncSuccess": "Synchronized issue successfully",

"noFileOpened": "No open files",
"currentNotMD": "The current file is not of the Markdown type",
"fileNotFound": "File not found: ",

"titleEmpty": "The title cannot be empty",
"unkonwnIssue": "Unknown Issue",
"unkonwnIssue": "Unknown issue, please set the issue_number.",
"createFail": "Failed to create issue",
"updateFail": "Failed to update issue",
"syncFail": "Failed to get issue",

"getRepositoryFail": "Failed to retrieve the list of repositories",
"noRepository": "You have not created a GitHub repository yet",
Expand Down
9 changes: 6 additions & 3 deletions l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
"requestAuth": "请求Github授权",
"unauthorized": "未获得授权",
"getRepository": "获取博客仓库",
"createIssue": "创建Issue",
"createIssue": "正在创建Issue",
"createSuccess": "创建Issue成功",
"viewInBrowser": "前往浏览器查看",
"updateIssue": "更新Issue",
"updateIssue": "正在更新Issue",
"updateSuccess": "更新Issue成功",
"syncIssue": "正在同步issue",
"syncSuccess": "同步Issue成功",

"noFileOpened": "没有打开的文件",
"currentNotMD": "当前文件不是Markdown类型",
"fileNotFound": "没有找到文件:",

"titleEmpty": "标题不能为空",
"unkonwnIssue": "未知的Issue",
"unkonwnIssue": "未知的Issue,请设置issue_number",
"createFail": "创建Issue失败",
"updateFail": "更新Issue失败",
"syncFail": "获取Issue失败",

"getRepositoryFail": "获取仓库列表失败",
"noRepository": "您还没有创建Github仓库",
Expand Down
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "github-issue-blog",
"displayName": "Github Issue Blog",
"description": "A vscode plugin to create a blog with issue",
"version": "0.0.1",
"version": "0.0.2",
"author": "wtto00",
"publisher": "wtto00",
"license": "MIT",
Expand All @@ -28,7 +28,8 @@
],
"activationEvents": [
"onCommand:github-issue-blog.create",
"onCommand:github-issue-blog.update"
"onCommand:github-issue-blog.update",
"onCommand:github-issue-blog.sync"
],
"main": "./out/extension.js",
"l10n": "./l10n",
Expand All @@ -41,6 +42,10 @@
{
"command": "github-issue-blog.update",
"title": "%commands.update%"
},
{
"command": "github-issue-blog.sync",
"title": "%commands.sync%"
}
],
"menus": {
Expand All @@ -54,6 +59,11 @@
"command": "github-issue-blog.update",
"group": "1_modification",
"when": "resourceLangId == markdown"
},
{
"command": "github-issue-blog.sync",
"group": "1_modification",
"when": "resourceLangId == markdown"
}
],
"editor/context": [
Expand All @@ -66,6 +76,11 @@
"command": "github-issue-blog.update",
"group": "1_modification",
"when": "resourceLangId == markdown"
},
{
"command": "github-issue-blog.sync",
"group": "1_modification",
"when": "resourceLangId == markdown"
}
],
"editor/title/context": [
Expand All @@ -78,6 +93,11 @@
"command": "github-issue-blog.update",
"group": "1_modification",
"when": "resourceLangId == markdown"
},
{
"command": "github-issue-blog.sync",
"group": "1_modification",
"when": "resourceLangId == markdown"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"commands.create": "Github Issue Blog: Create Issue",
"commands.update": "Github Issue Blog: Update Issue",
"commands.sync": "Github Issue Blog: Sync Issue",

"configuration.repo": "repository name of Github (eg. wtto00/github-issue-blog)"
}
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"commands.create": "Github Issue Blog: 创建Issue",
"commands.update": "Github Issue Blog: 更新Issue",
"commands.sync": "Github Issue Blog: 同步Issue",

"configuration.repo": "博客所属的Github仓库名称(例如:wtto00/github-issue-blog)"
}
26 changes: 18 additions & 8 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export class Command {
const url = await this.github!.createIssue();

this.statusBarItem.hide();
const btn = await vscode.window.showInformationMessage(
l10n.t("createSuccess"),
l10n.t("viewInBrowser")
);
const btn = await vscode.window.showInformationMessage(l10n.t("createSuccess"), l10n.t("viewInBrowser"));
if (btn) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -78,10 +75,7 @@ export class Command {
const url = await this.github!.updateIssue();

this.statusBarItem.hide();
const btn = await vscode.window.showInformationMessage(
l10n.t("updateSuccess"),
l10n.t("viewInBrowser")
);
const btn = await vscode.window.showInformationMessage(l10n.t("updateSuccess"), l10n.t("viewInBrowser"));
if (btn) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -93,6 +87,22 @@ export class Command {
}
};

syncIssue = async (uri: vscode.Uri) => {
try {
this.statusBarItem.show();
await this.prepare(uri);

this.statusBarItem.text = `$(sync~spin) ${l10n.t("syncIssue")}...`;
await this.github!.syncIssue();

this.statusBarItem.hide();
vscode.window.showInformationMessage(l10n.t("syncSuccess"));
} catch (error) {
vscode.window.showErrorMessage((error as Error).message);
this.statusBarItem.hide();
}
};

getIssueList = async (uri: vscode.Uri) => {
try {
this.statusBarItem.show();
Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export async function activate(context: vscode.ExtensionContext) {

const _createIssue = vscode.commands.registerCommand("github-issue-blog.create", command.createIssue);
const _updateIssue = vscode.commands.registerCommand("github-issue-blog.update", command.updateIssue);
const _syncIssue = vscode.commands.registerCommand("github-issue-blog.sync", command.syncIssue);

context.subscriptions.push(_createIssue, _updateIssue);
context.subscriptions.push(_createIssue, _updateIssue, _syncIssue);
}

export function deactivate() {
Expand Down
4 changes: 2 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class FileUtil {
this.issueData = matter(md);
}

updateMDContent = async (overrideMatterData: MatterData) => {
updateMDContent = async (overrideMatterData: MatterData, content?: string) => {
if (vscode.window.activeTextEditor?.document.fileName !== this.uri.fsPath) {
const document = await vscode.workspace.openTextDocument(this.uri);
await vscode.window.showTextDocument(document);
Expand All @@ -64,7 +64,7 @@ export class FileUtil {
const originText = activeTextEditor.document.getText();
this.issueData = matter(originText);
const md = matter.stringify(
{ content: this.issueData.content },
{ content: "\n" + (content ?? this.issueData.content).trimStart() },
{ ...this.issueData.data, ...overrideMatterData }
);
editBuilder.replace(
Expand Down
22 changes: 22 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ export class Github {
return res.data.html_url;
}

async syncIssue() {
const { data = {} } = this.file.issueData;
const { issue_number = 0 } = data;
this.checkId();
const res = await this.octokit.rest.issues.get({
owner: this.repo.owner,
repo: this.repo.repo,
issue_number: issue_number,
});
if (!res.data) throw Error(l10n.t("syncFail"));
this.file.updateMDContent(
{
title: res.data.title,
issue_number,
labels: res.data.labels
.map((label) => (typeof label === "string" ? label : label.name!))
.filter((label) => label),
},
res.data.body || ""
);
}

async getIssueList() {
const res = await this.octokit.rest.issues.listForRepo({
owner: this.repo.owner,
Expand Down

0 comments on commit 50b31f1

Please sign in to comment.