Filter related commits in repository
(path, {ref})
| 90 | |
| 91 | /**Filter related commits in repository */ |
| 92 | async filter(path, {ref}) { |
| 93 | const commits = new Set() |
| 94 | try { |
| 95 | this.debug(`filtering commits authored by ${this.login} in ${path}`) |
| 96 | for (const author of this.authoring) { |
| 97 | //Search by --author |
| 98 | { |
| 99 | const output = await this.shell.run(`git log --author='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false}) |
| 100 | const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line)) |
| 101 | hashes.forEach(hash => commits.add(hash)) |
| 102 | this.debug(`found ${hashes.length} for ${author} (using --author)`) |
| 103 | } |
| 104 | //Search by --grep |
| 105 | { |
| 106 | const output = await this.shell.run(`git log --grep='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false}) |
| 107 | const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line)) |
| 108 | hashes.forEach(hash => commits.add(hash)) |
| 109 | this.debug(`found ${hashes.length} for ${author} (using --grep)`) |
| 110 | } |
| 111 | } |
| 112 | //Apply ref range if specified |
| 113 | if (ref) { |
| 114 | this.debug(`filtering commits referenced by ${ref} in ${path}`) |
| 115 | const output = await this.shell.run(`git rev-list --boundary ${ref}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false}) |
| 116 | const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line)) |
| 117 | commits.forEach(commit => !hashes.includes(commit) ? commits.delete(commit) : null) |
| 118 | } |
| 119 | this.debug(`found ${commits.size} unique commits authored by ${this.login} in ${path}`) |
| 120 | } |
| 121 | catch (error) { |
| 122 | this.debug(`an error occurred during filtering of commits authored by ${this.login} in ${path} (${error})`) |
| 123 | } |
| 124 | return [...commits] |
| 125 | } |
| 126 | |
| 127 | /**Filter commits in repository */ |
| 128 | async commits(path, {ref}) { |