Skip to content

Comments

feat: employees#16

Open
iugo wants to merge 13 commits intomainfrom
feat-employees
Open

feat: employees#16
iugo wants to merge 13 commits intomainfrom
feat-employees

Conversation

@iugo
Copy link
Member

@iugo iugo commented Nov 7, 2025

close #15
close #14

@gemini-code-assist
Copy link

Summary of Changes

Hello @iugo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the project's capabilities by integrating a new feature to fetch employee field configurations from the WeChat Work API. Concurrently, it refines the development workflow and code quality through the standardization of code style, comprehensive Deno configuration for linting and formatting, and the establishment of a more robust logging and debugging infrastructure. These changes collectively aim to improve developer experience, maintain code consistency, and prepare the codebase for future API extensions.

Highlights

  • New Employee Field API Integration: Introduced a new API endpoint and associated types (getFields) to retrieve employee field configurations from the WeChat Work platform, addressing issue feat: 人事助手-花名册 #15.
  • Standardized Development Environment: Added .editorconfig, .gitignore, and .vscode/setting.json to enforce consistent code style, manage ignored files, and configure VS Code for Deno development, including linting and format-on-save.
  • Enhanced Deno Configuration: Updated deno.json to include comprehensive linting and formatting rules, and integrated @std/path for improved path manipulation.
  • Improved Logging and Debugging System: Implemented a new src/constants.ts for a global verbose flag and src/log.ts for structured logging, featuring conditional debug output and file-based debug logging.
  • Standardized SDK Options: Introduced a new SDKOptions type definition in src/basetypes.ts to standardize common parameters for SDK functions, such as accessToken, optional debug callback, and an optional proxy string.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds functionality for fetching employee fields from the WeChat Work API, along with related configurations and helper utilities for logging and constants. The changes are a good step towards building out the SDK's features.

My review includes several points:

  • A critical bug in how the proxy URL is constructed.
  • Missing error handling for network requests and lack of assertions in tests, which are high-severity issues affecting correctness and reliability.
  • Suggestions to improve performance by using asynchronous I/O for logging.
  • Several medium-severity suggestions for improving code consistency and maintainability, such as standardizing comment languages.

Overall, the code is well-structured, but addressing these points will significantly improve its robustness and quality.

}: SDKOptions): Promise<QywechatRes<{ group_list: FieldGroup[] }>> {
const domain = 'qyapi.weixin.qq.com';
const path = '/cgi-bin/hr/get_fields';
const url = new URL(`https://${proxy ?? ''}${domain}${path}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The current URL construction with the proxy seems incorrect. It concatenates the proxy and the domain (https://${proxy ?? ''}${domain}${path}), which will result in an invalid URL like https://myproxy.com/qyapi.weixin.qq.com/.... The proxy should likely replace the domain if provided.

Suggested change
const url = new URL(`https://${proxy ?? ''}${domain}${path}`);
const url = new URL(`https://${proxy ?? domain}${path}`);

Comment on lines 16 to 19
Deno.test('getFields', async () => {
const res = await getFields({ accessToken, proxy });
debug('getFields res:', res);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test executes getFields but lacks assertions to verify the response is correct. A test should validate the function's output.

I'd suggest:

  1. Adding assertions to check for a successful response (errcode: 0) and that the group_list data exists.
  2. Awaiting the debug call, assuming you make it asynchronous to avoid blocking I/O as suggested in another comment for src/log.ts.

To use assertEquals and assertExists, you'll need to import them:

import { assertEquals, assertExists } from '@std/assert';
Suggested change
Deno.test('getFields', async () => {
const res = await getFields({ accessToken, proxy });
debug('getFields res:', res);
});
Deno.test('getFields', async () => {
const res = await getFields({ accessToken, proxy });
await debug('getFields res:', res);
assertEquals(res.errcode, 0);
assertExists(res.group_list);
});

Comment on lines +21 to +22
const res = await fetch(url);
const data = await res.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The fetch call does not check if the response was successful (e.g., HTTP status 200-299). If the server returns an error status like 404 or 500, res.json() might fail or you might return an unexpected structure. It's good practice to check res.ok and handle non-successful responses explicitly.

  const res = await fetch(url);
  if (!res.ok) {
    throw new Error(`Failed to get fields: ${res.status} ${await res.text()}`);
  }
  const data = await res.json();

Comment on lines +52 to +54
* 设置
* @param value
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSDoc for setVerbose is in Chinese, while the function name and other comments in this file are in English. For consistency and better maintainability, it's recommended to use English for all documentation within this file.

/**
 * Sets the verbose flag.
 * @param value
 */

const path = '/cgi-bin/hr/get_fields';
const url = new URL(`https://${proxy ?? ''}${domain}${path}`);
url.searchParams.set('access_token', accessToken);
debug('getFields url:', url);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the debug function is made asynchronous (as suggested for src/log.ts to avoid blocking I/O), this call should be awaited to ensure proper execution and error handling.

Suggested change
debug('getFields url:', url);
await debug('getFields url:', url);

debug('getFields url:', url);
const res = await fetch(url);
const data = await res.json();
debug('getFields response:', data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the debug function is made asynchronous (as suggested for src/log.ts to avoid blocking I/O), this call should be awaited to ensure proper execution and error handling.

  await debug('getFields response:', data);

Comment on lines +58 to +63
TEXT = 1, // 文本
SELECT = 2, // 选项
TIME = 3, // 时间
IMAGE = 4, // 图片
FILE_SINGLE = 5, // 单个文件
FILE_MULTI = 6, // 多个文件

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comments for the FieldType enum values are in Chinese. For consistency with the rest of the codebase which primarily uses English for comments and identifiers, it would be better to translate these comments to English.

  TEXT = 1, // Text
  SELECT = 2, // Select
  TIME = 3, // Time
  IMAGE = 4, // Image
  FILE_SINGLE = 5, // Single file
  FILE_MULTI = 6, // Multiple files

Comment on lines +9 to +18
export const debug = (...args: unknown[]) => {
if (isVerbose()) {
console.log(...args);

Deno.writeTextFileSync(
resolve(import.meta.dirname!, '../temp/debug.json'),
JSON.stringify(args, null, 2),
);
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The debug function uses Deno.writeTextFileSync, which is a synchronous and blocking I/O operation. If debug is called frequently, this could impact performance. Consider using the asynchronous version Deno.writeTextFile to avoid blocking the event loop. This will require making the debug function async.

Suggested change
export const debug = (...args: unknown[]) => {
if (isVerbose()) {
console.log(...args);
Deno.writeTextFileSync(
resolve(import.meta.dirname!, '../temp/debug.json'),
JSON.stringify(args, null, 2),
);
}
};
export const debug = async (...args: unknown[]) => {
if (isVerbose()) {
console.log(...args);
await Deno.writeTextFile(
resolve(import.meta.dirname!, '../temp/debug.json'),
JSON.stringify(args, null, 2),
);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: 人事助手-花名册 feat: 通讯录管理-获取成员ID列表

1 participant