首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Danger.js添加和删除中排除文件

从Danger.js添加和删除中排除文件
EN

Stack Overflow用户
提问于 2020-12-22 01:22:32
回答 1查看 696关注 0票数 0

我们正在尝试在prs中设置最大行更改,但注意到有一些元文件很容易超过这个限制,例如yarn.lock。

有人知道如何从添加和删除中排除文件吗?

代码语言:javascript
复制
// ...

const linesAdded = danger.github.pr.additions || 0;
const linesRemoved = danger.github.pr.deletions || 0;

// ...

if (linesAdded + linesRemoved > bigPRThreshold) {
  fail(
    `This PR size is too large (Over ${bigPRThreshold} lines. Please split into separate PRs to enable faster & easier review.`
  );
}

// ...
EN

回答 1

Stack Overflow用户

发布于 2021-02-05 06:48:09

我发现以下gitDSL函数可以访问单个文件中的信息

代码语言:javascript
复制
//This should make it really easy to do work when specific keypaths have changed inside a JSON file.
JSONDiffForFile(filename: string) => Promise

// Provides a JSON patch (rfc6902) between the two versions of a JSON file, returns null if you don't have any changes for the file in the diff.

// Note that if you are looking to just see changes like: before, after, added or removed - you should use `JSONDiffForFile` instead, as this can be a bit unwieldy for a Dangerfile.
JSONPatchForFile(filename: string) => Promise

// Offers the diff for a specific file
diffForFile(filename: string) => Promise

// Offers the overall lines of code added/removed in the diff
linesOfCode() => Promise

// Offers the structured diff for a specific file
structuredDiffForFile(filename: string) => Promise

(有关这些函数的文档:https://danger.systems/js/reference.html#GitDSL)

使用danger.git.structuredDiffForFile,我可以计算出我想要排除的行

代码语言:javascript
复制
  const file = 'yarn.lock';
  const diff1 = await danger.git.structuredDiffForFile(file);
  const excludedLines = diff1.chunks[0].changes.length
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65397239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档