File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
codeql-custom-queries-java/queries/recommendations Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments