Skip to content

Commit

Permalink
chore: core-label use prAuthor
Browse files Browse the repository at this point in the history
* chore: core-label use prAuthor

* fix
  • Loading branch information
thinkasany authored Sep 14, 2023
1 parent e6c6ac7 commit 907fc23
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
66 changes: 48 additions & 18 deletions app/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,55 @@ const getTeamMembers = async payload => {
}
};

const getPRCommitAuthors = async payload => {
// const getPRCommitAuthors = async payload => {
// const { repo, owner, token, prNumber } = payload;

// const apiUrl = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/commits`;
// const headers = {
// Authorization: `Bearer ${token}`,
// Accept: "application/vnd.github.v3+json",
// "User-Agent": "GitHub-PR-Commits"
// };
// console.log('getPRCommitAuthors', apiUrl);

// try {
// const response = await axios.get(apiUrl, { headers });

// if (response.status === 200) {
// const commitAuthors = response.data.map(
// commit => commit.author.login
// );
// return commitAuthors;
// } else {
// throw new Error(`无法获取提交列表: ${response.data.message}`);
// }
// } catch (error) {
// console.log('getPRCommitAuthors err', error);
// throw new Error(`发生错误: ${error.message}`);
// }
// };

const getPRAuthor = async payload => {
const { repo, owner, token, prNumber } = payload;

const apiUrl = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/commits`;
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}`;
const headers = {
Authorization: `Bearer ${token}`,
Accept: "application/vnd.github.v3+json",
"User-Agent": "GitHub-PR-Commits"
Accept: "application/vnd.github.v3+json"
};
console.log('getPRCommitAuthors', apiUrl);
console.log("getPRAuthor", apiUrl);

try {
const response = await axios.get(apiUrl, { headers });

if (response.status === 200) {
const commitAuthors = response.data.map(
commit => commit.author.login
);
return commitAuthors;
const prAuthor = response.data.user.login;
return prAuthor;
} else {
throw new Error(`无法获取提交列表: ${response.data.message}`);
throw new Error(`无法获取: ${response.data.message}`);
}
} catch (error) {
console.log('getPRCommitAuthors err', error);
console.log("getPRAuthor err", error);
throw new Error(`发生错误: ${error.message}`);
}
};
Expand All @@ -132,13 +157,18 @@ const Action = async payload => {
if (isEnableTeamLabel) {
// 是否开启功能:添加 teamLabel 的label
try {
const commitAuthors = await getPRCommitAuthors(payload);
console.log("PR 中的提交者名字列表:", commitAuthors);
for (const author of commitAuthors) {
if (coreTeam.includes(author)) {
await addLabelToPR({ ...payload, files: [teamLabel] });
break;
}
// const commitAuthors = await getPRCommitAuthors(payload);
// console.log("PR 中的提交者名字列表:", commitAuthors);
// for (const author of commitAuthors) {
// if (coreTeam.includes(author)) {
// await addLabelToPR({ ...payload, files: [teamLabel] });
// break;
// }
// }
const prAuthor = await getPRAuthor(payload);
console.log("PR 提交者:", prAuthor);
if (coreTeam.includes(prAuthor)) {
await addLabelToPR({ ...payload, files: [teamLabel] });
}
} catch (error) {
console.error(error.message);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

0 comments on commit 907fc23

Please sign in to comment.