|
| 1 | +any_mismatch = FALSE |
| 2 | + |
| 3 | +# ensure that numbered list in each section is in sequence |
| 4 | +check_section_numbering = function(news) { |
| 5 | + # plain '#' catches some examples; 'd' for 'data.table' |
| 6 | + sections = grep("^#+ [A-Zd]", news) |
| 7 | + entries = grep("^[0-9]+[.]", news) |
| 8 | + entry_value = as.integer(gsub("^([0-9]+)[.].*", "\\1", news[entries])) |
| 9 | + section_id = findInterval(entries, sections) |
| 10 | + |
| 11 | + any_mismatch = FALSE |
| 12 | + for (id in unique(section_id)) { |
| 13 | + section_entries = entry_value[section_id == id] |
| 14 | + intended_value = seq_along(section_entries) |
| 15 | + matched = section_entries == intended_value |
| 16 | + if (all(matched)) next |
| 17 | + any_mismatch = TRUE |
| 18 | + section_header = news[sections[id]] |
| 19 | + cat(sprintf( |
| 20 | + "In section '%s' (line %d), bad numbering:\n%s\n", |
| 21 | + section_header, sections[id], |
| 22 | + paste0(" [", section_entries[!matched], " --> ", intended_value[!matched], "]", collapse="\n") |
| 23 | + )) |
| 24 | + } |
| 25 | + return(any_mismatch) |
| 26 | +} |
| 27 | + |
| 28 | +# ensure that GitHub link text & URL actually agree |
| 29 | +check_gh_links = function(news) { |
| 30 | + gh_links_info = gregexpr( |
| 31 | + "\\[#(?<md_number>[0-9]+)\\]\\(https://github.com/Rdatatable/data.table/(?<link_type>[^/]+)/(?<link_number>[0-9]+)\\)", |
| 32 | + news, |
| 33 | + perl=TRUE # required for within-group indices |
| 34 | + ) |
| 35 | + gh_link_metadata = do.call(rbind, lapply(seq_along(gh_links_info), function(idx) { |
| 36 | + x = gh_links_info[[idx]] |
| 37 | + if (x[1L] <= 0L) return(NULL) |
| 38 | + match_mat = attr(x, "capture.start") # matrix seeded with the correct dimensions |
| 39 | + match_mat[] = substring(news[idx], match_mat, match_mat + attr(x, "capture.length") - 1L) |
| 40 | + match_df = data.frame(match_mat) |
| 41 | + match_df$line_number = idx |
| 42 | + match_df |
| 43 | + })) |
| 44 | + matched = gh_link_metadata$md_number == gh_link_metadata$link_number |
| 45 | + if (all(matched)) return(FALSE) |
| 46 | + |
| 47 | + cat(sep = "", with(gh_link_metadata[!matched, ], sprintf( |
| 48 | + "In line %d, link pointing to %s %s is written #%s\n", |
| 49 | + line_number, link_type, link_number, md_number |
| 50 | + ))) |
| 51 | + return(TRUE) |
| 52 | +} |
| 53 | + |
| 54 | +any_error = FALSE |
| 55 | +for (news in list.files(pattern = "NEWS")) { |
| 56 | + cat(sprintf("Checking NEWS file %s...\n", news)) |
| 57 | + news_lines = readLines(news) |
| 58 | + any_error = check_section_numbering(news_lines) || any_error |
| 59 | + any_error = check_gh_links(news_lines) || any_error |
| 60 | +} |
| 61 | +if (any_error) stop("Please fix the NEWS issues above.") |
0 commit comments