Skip to content

Commit 102663e

Browse files
committed
Add comment-non-perma-GitHub-url.ql
1 parent b28673a commit 102663e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Finds comments which contain a non-permalink GitHub URL, for example
3+
* `https://github.com/myorg/myrepo/blob/master/SomeClass.java#123`.
4+
*
5+
* If the referenced file is updated, renamed or removed, or if the branch is deleted or renamed
6+
* such URLs could become dead links, which requires some effort to then find out what the URL
7+
* was originally referring to.
8+
*
9+
* Prefer either permalinks with commit SHA, by clicking the three dots at the top right in the
10+
* GitHub UI and selecting "Copy permalink". Or instead of referencing branches such as `master`
11+
* or `main` use a reference to a version tag instead, e.g. `v1.0.0`.
12+
*
13+
* @id todo
14+
* @kind problem
15+
*/
16+
17+
import java
18+
19+
// Javadoc covers regular comments as well
20+
from JavadocText comment
21+
where
22+
exists(
23+
// Only cover common default branch names; otherwise even when not using a commit SHA, the
24+
// reference can be stable in case it refers to a tag
25+
comment
26+
.getText()
27+
// Patterns for user and repo name are based on validation messages in GitHub UI
28+
.regexpFind("https://github\\.com/[a-zA-Z0-9\\-]+/[a-zA-Z0-9.\\-_]+/blob/(master|main)/", _, _)
29+
)
30+
select comment, "Uses non-permalink GitHub URL"

0 commit comments

Comments
 (0)