gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite53d284be53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mree53d284b/lib/pullsync.hl

19.4 KB

  1. // lib/pullsync.hl — PULL REQUEST RECORDS (gitoria#40, part of the push API #38; contract docs/apps-api.md §3, §4).
  2. // A pull request is still a commit whose subject starts `|||PR` (git-helpers.hl parsePull), but now it is also STORED, so it has
  3. // a number that never changes and is never reused. Two tables, both keyed by the repo's ID (never the slug: a repo can be renamed):
  4. // pullRecs pk @id index !key, !shaKey, repo { rid (the repo's @id), number, key "<repo>#<n>", shaKey "<repo> <sha>", sha (the |||PR commit), source,
  5. // target, implicit (the target is the repo's main branch), state open|closed|merged, head, authorId, authorName,
  6. // heads (every head the PR has had, oldest first: an app may review an earlier one), createdMs, updatedMs } storage/mpackdb/pullrecs.db
  7. // pullInit pk @id index !repo { rid } a repo whose PRs were numbered once (the numbers of the old ones, oldest first)
  8. // ensurePulls(slug) numbers the PRs a repo already has, once, without changes (before the first push / page view)
  9. // syncPulls(slug, userId) compares git with the records → the CHANGES (opened|reopened|synchronize|closed|merged), each with the
  10. // ref refs/pull/<n>/head already pointing at the new head; logChange writes them (until gitoria#43 sends events)
  11. // pullObject(slug, n) the contract's `pull` JSON; withNumbers(list, slug) puts "#N" on the rows of /pulls.
  12. // A record is found again by the sha of its |||PR commit (that is what identifies a PR to git); its source branch may be renamed.
  13. // Merged is final. Nothing here throws: a failed git call skips that PR until the next sync.
  14. import { MPackDB } from 'hl:mpackdb'
  15. import { now, timestamp } from 'hl:time'
  16. import { appendFile, mkDir } from 'hl:fs'
  17. import { run } from 'hl:proc'
  18. import { randomBytes } from 'hl:crypto'
  19. import { NL, storageDir, countOfList, firstOf, repoOrigin, px } from './util.hl'
  20. import { repoBySlug } from './repos.hl'
  21. import { nameOfUser } from './users.hl'
  22. import { gitRaw, pickDefault } from './git.hl'
  23. import { tabs, isHexId, safeName, parsePull } from './git-helpers.hl'
  24. import { bodyOfLines, ticketNames } from './pullsync-helpers.hl'
  25. import { approvalsOf } from './approvals.hl'
  26. import { approvalsJson } from './approvals-helpers.hl'
  27. import { statusesOf, statusJson, requiredOf, approversOf } from './statuses.hl'
  28. static pullRecs = new MPackDB(file = storageDir + '/pullrecs.db', primaryKey = '@id', indexes = ['!key', '!shaKey', 'rid'])
  29. static pullInit = new MPackDB(file = storageDir + '/pullinit.db', primaryKey = '@id', indexes = ['!rid'])
  30. static changeLog = storageDir + '/pull-changes.log'
  31. static maxNew = 50
  32. static scan = 500
  33. static zeroId = '0000000000000000000000000000000000000000'
  34. // Atomic mkdir owns a PR's read/replace section across containers.
  35. // A short flock guard serializes lease creation, expiry and release, including owner-file setup.
  36. // The directory expires after a minute if a worker dies; the token prevents an old release removing a new lease.
  37. static pullClaimDir = storageDir + '/pull-claims'
  38. static claimPull = (String id) => {
  39. mkDir(pullClaimDir, 448)
  40. path = pullClaimDir + '/' + id
  41. token = randomBytes(12, 'hex')
  42. script = 'if [ -d "$1" ] && [ -n "$(find "$1" -maxdepth 0 -mmin +1 -print)" ]; then rm -f "$1/owner"; rmdir "$1" || exit 1; fi
  43. mkdir "$1" 2>/dev/null || exit 1
  44. printf "%s" "$2" > "$1/owner"'
  45. r = run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', path, token], { timeout = 5 })
  46. return r != null && r.exit == 0 ? { path = path token = token } : null
  47. }
  48. static releasePull = (Hybrid claim) => {
  49. script = 'if [ "$(cat "$1/owner" 2>/dev/null)" = "$2" ]; then rm -f "$1/owner"; rmdir "$1"; fi'
  50. run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', claim.path, claim.token], { timeout = 5 })
  51. return null
  52. }
  53. // ---- small git answers -------------------------------------------------------------------------------------
  54. // the first line of a git call's output, or '' (failed, nothing, or not a plain id when `hexOnly`)
  55. static firstLine = (slug, args) => {
  56. r = gitRaw(slug, args)
  57. if (r == null || r.exit != 0 || r.lines.length == 0) { return '' }
  58. return r.lines[0]
  59. }
  60. static isAncestor = (slug, a, b) => {
  61. if (a == null || b == null || a == '' || b == '') { return false }
  62. r = gitRaw(slug, ['merge-base', '--is-ancestor', a, b])
  63. return r != null && r.exit == 0
  64. }
  65. // { name: tip sha } of every branch, and the names in order
  66. static branchTips = (slug) => {
  67. tips = {}
  68. names = []
  69. r = gitRaw(slug, ['for-each-ref', '--format=%(refname:short)%09%(objectname)', 'refs/heads'])
  70. if (r != null && r.exit == 0) {
  71. for (l of r.lines) {
  72. f = tabs(l)
  73. if (f.length == 2 && safeName(f[0]) && isHexId(f[1])) {
  74. tips[f[0]] = f[1]
  75. names.push(f[0])
  76. }
  77. }
  78. }
  79. return { tips = tips names = names ok = r != null && r.exit == 0 }
  80. }
  81. // The recorded source wins while it contains the marker. Without one, prefer the known head's
  82. // branch before another branch that merely contains the marker (for example a later PR).
  83. static sourceOf = (String slug, String sha, String target, String preferred, String head) => {
  84. return sourceResult(slug, sha, target, preferred, head).source
  85. }
  86. // The list cache also needs to know whether EVERY git read succeeded. Keep sourceOf's string contract.
  87. static sourceResult = (String slug, String sha, String target, String preferred, String head) => {
  88. r = gitRaw(slug, ['for-each-ref', '--contains', sha, '--format=%(refname:short)%09%(objectname)', 'refs/heads'])
  89. if (r == null || r.exit != 0) { return { source = '' ok = false } }
  90. candidates = []
  91. for (l of r.lines) {
  92. f = tabs(l)
  93. if (f.length == 2 && safeName(f[0]) && f[0] != target && isHexId(f[1])) {
  94. if (f[0] == preferred) { return { source = f[0] ok = true } }
  95. candidates.push({ name = f[0] tip = f[1] })
  96. }
  97. }
  98. knownHead = head == null || head == '' ? sha : head
  99. for (c of candidates) { if (c.tip == knownHead) { return { source = c.name ok = true } } }
  100. let complete = true
  101. for (c of candidates) {
  102. ancestor = gitRaw(slug, ['merge-base', '--is-ancestor', knownHead, c.tip])
  103. if (ancestor == null || (ancestor.exit != 0 && ancestor.exit != 1)) { complete = false }
  104. if (ancestor != null && ancestor.exit == 0) { return { source = c.name ok = complete } }
  105. }
  106. return { source = candidates.length > 0 ? candidates[0].name : '' ok = complete }
  107. }
  108. // the commit that put the PR into the target: the first one on the target's first-parent line that has the PR commit as an ancestor
  109. // (the merge commit of the Merge button; a fast-forward's commit itself); the target's tip when git cannot say
  110. static mergeCommitOf = (slug, sha, targetTip) => {
  111. r = gitRaw(slug, ['rev-list', '--first-parent', '--ancestry-path', '--reverse', sha + '..' + targetTip])
  112. if (r != null && r.exit == 0 && r.lines.length > 0 && isHexId(r.lines[0])) { return r.lines[0] }
  113. return targetTip
  114. }
  115. // ---- the refs/pull/N/head ref (and refs/pull/N/heads/<sha> for every head it ever had) ----------------------------------------------------------------------------
  116. // point it at `head`, with the old value given (a ref that is not there must not be there). → true when it points there afterwards
  117. static setPullRef = (slug, n, head) => {
  118. ref = 'refs/pull/' + n + '/head'
  119. cur = firstLine(slug, ['rev-parse', '--verify', '-q', ref])
  120. if (cur == head) { return true }
  121. r = gitRaw(slug, ['update-ref', '-m', 'pull request ' + n, ref, head, cur == '' ? zeroId : cur])
  122. if (r == null || r.exit != 0) { return false }
  123. // every head stays referenced (refs/pull/N/heads/<sha>, hidden like the rest of refs/pull): an app may review an earlier head, git gc must not drop it
  124. gitRaw(slug, ['update-ref', '-m', 'pull request ' + n + ' head', 'refs/pull/' + n + '/heads/' + head, head])
  125. return true
  126. }
  127. // ---- the records -------------------------------------------------------------------------------------------
  128. static recordsOf = (repoId) => {
  129. all = pullRecs.find('rid', repoId)
  130. return countOfList(all) == 0 ? [] : all
  131. }
  132. static recordBySha = (repoId, sha) => { return firstOf(pullRecs.find('shaKey', repoId + ' ' + sha)) }
  133. static recordByNumber = (repoId, n) => { return firstOf(pullRecs.find('key', repoId + '#' + n)) }
  134. // the next number: one more than the highest (records are never removed, so a number is never used twice)
  135. static nextNumber = (repoId) => {
  136. let top = 0
  137. for (r of recordsOf(repoId)) { if (r.number > top) { top = r.number } }
  138. return top + 1
  139. }
  140. // every head the record has had (a list of shas); the current one is always in it
  141. static headsOf = (rec) => {
  142. out = []
  143. if (rec.heads != null && countOfList(rec.heads) > 0) { for (h of rec.heads) { out.push(h) } }
  144. if (rec.head != null && !out.includes(rec.head)) { out.push(rec.head) }
  145. return out
  146. }
  147. static withHead = (rec, head) => {
  148. out = headsOf(rec)
  149. if (!out.includes(head)) { out.push(head) }
  150. return out
  151. }
  152. // was this sha ever a head of pull request N of the repo? (gitoria#44: a review of an earlier head is fine, only a sha that never was one is stale)
  153. static wasHeadOf = (slug, n, sha) => {
  154. repo = repoBySlug(slug)
  155. if (repo == null || n == null || sha == null || hlTypeName(sha) != 'String') { return false }
  156. rec = recordByNumber(repo.id, n)
  157. return rec != null && headsOf(rec).includes(sha)
  158. }
  159. static isInitialized = (repoId) => { return firstOf(pullInit.find('rid', repoId)) != null }
  160. static changeOf = (rec, action, before, after, forced, mergeCommit, pusherId) => {
  161. let sender = null
  162. if (pusherId != null) { sender = { id = pusherId name = nameOfUser(pusherId) } }
  163. return { number = rec.number action = action before = before after = after forced = forced mergeCommit = mergeCommit sender = sender }
  164. }
  165. // the commits of the repo that start a pull request, oldest first, not yet stored: [{ sha, ct, author, parsed }]
  166. static newCandidates = (slug, repoId) => {
  167. out = []
  168. lg = gitRaw(slug, ['log', '-' + scan, '--branches', '--format=%H%x09%ct%x09%an%x09%s'])
  169. if (lg == null || lg.exit != 0) { return out }
  170. for (l of lg.lines) {
  171. f = tabs(l)
  172. if (f.length >= 4 && isHexId(f[0]) && f[0].length == 40) {
  173. pr = parsePull(f.slice(3).join(' '))
  174. if (pr != null && out.length < maxNew && recordBySha(repoId, f[0]) == null) {
  175. out.push({ sha = f[0] ct = toNumber(f[1]) * 1000 author = f[2] parsed = pr })
  176. }
  177. }
  178. }
  179. // commit time, oldest first (an insertion sort: no sort(), hybriel #1)
  180. let i = 1
  181. while (i < out.length) {
  182. cur = out[i]
  183. let j = i - 1
  184. while (j >= 0 && out[j].ct > cur.ct) {
  185. out[j + 1] = out[j]
  186. j = j - 1
  187. }
  188. out[j + 1] = cur
  189. i = i + 1
  190. }
  191. return out
  192. }
  193. // the whole comparison. quiet = number the existing PRs and return no changes (ensurePulls). → the changes (a list)
  194. static syncNow = (slug, pusherId, quiet) => {
  195. changes = []
  196. repo = repoBySlug(slug)
  197. if (repo == null) { return changes }
  198. bt = branchTips(slug)
  199. if (!bt.ok) { return changes }
  200. dflt = pickDefault(bt.names, repo.branch)
  201. stamp = now()
  202. // 1. the PRs we know
  203. for (rec of recordsOf(repo.id)) {
  204. if (rec.state != 'merged') {
  205. target = rec.implicit == true && dflt != null ? dflt : rec.target
  206. targetTip = bt.tips[target]
  207. let source = rec.source
  208. let tip = source != '' ? bt.tips[source] : null
  209. let onBranch = tip != null && isAncestor(slug, rec.sha, tip)
  210. if (!onBranch) {
  211. // the commit may sit on another branch now (the branch was renamed)
  212. other = sourceOf(slug, rec.sha, target, rec.source, rec.head)
  213. if (other != '' && bt.tips[other] != null) {
  214. source = other
  215. tip = bt.tips[other]
  216. onBranch = true
  217. }
  218. }
  219. u = rec
  220. u.target = target
  221. u.source = source
  222. let action = ''
  223. let before = rec.head
  224. let after = rec.head
  225. let forced = false
  226. let mergeCommit = null
  227. if (targetTip != null && isAncestor(slug, rec.sha, targetTip)) {
  228. action = 'merged'
  229. u.state = 'merged'
  230. if (onBranch) { after = tip }
  231. mergeCommit = mergeCommitOf(slug, rec.sha, targetTip)
  232. } else if (onBranch && rec.state == 'closed' && rec.manualClosedBy == null) {
  233. action = 'reopened'
  234. u.state = 'open'
  235. after = tip
  236. } else if (onBranch && tip != rec.head) {
  237. action = 'synchronize'
  238. after = tip
  239. forced = !isAncestor(slug, rec.head, tip)
  240. } else if (!onBranch && rec.state == 'open') {
  241. action = 'closed'
  242. u.state = 'closed'
  243. }
  244. u.head = after
  245. u.heads = withHead(rec, after)
  246. if (action != '' || source != rec.source || target != rec.target) {
  247. // the ref first: an event is only sent for a head that can be fetched
  248. if (action == '' || setPullRef(slug, rec.number, after)) {
  249. // Git calls yield: another request/container may have closed or reopened this PR.
  250. // Read after the final git call, immediately before replacing the row.
  251. claim = claimPull(rec.id)
  252. if (claim == null) { continue }
  253. latest = pullRecs.fetch(rec.id)
  254. if (latest == null || latest.state == 'merged') { releasePull(claim) continue }
  255. u.manualClosedBy = latest.manualClosedBy
  256. u.manualClosedMs = latest.manualClosedMs
  257. if (u.state != 'merged' && latest.manualClosedBy != null) {
  258. u.state = 'closed'
  259. if (action == 'reopened') { action = '' }
  260. } else if (u.state != 'merged' && onBranch && rec.manualClosedBy != null && latest.manualClosedBy == null) {
  261. u.state = latest.state
  262. }
  263. u.heads = withHead(latest, after)
  264. u.updatedMs = stamp
  265. pullRecs.update(rec.id, u)
  266. releasePull(claim)
  267. if (action != '' && !quiet) { changes.push(changeOf(u, action, before, after, forced, mergeCommit, pusherId)) }
  268. }
  269. }
  270. }
  271. }
  272. // 2. the PRs we have not seen, oldest first (numbers follow the commit time)
  273. for (c of newCandidates(slug, repo.id)) {
  274. target = c.parsed.target == '' ? dflt : c.parsed.target
  275. targetTip = bt.tips[target]
  276. source = sourceOf(slug, c.sha, target)
  277. merged = targetTip != null && isAncestor(slug, c.sha, targetTip)
  278. if (merged || (source != '' && bt.tips[source] != null)) {
  279. head = !merged && source != '' ? bt.tips[source] : c.sha
  280. n = nextNumber(repo.id)
  281. author = quiet || pusherId == null ? null : pusherId
  282. rec = { rid = repo.id number = n key = repo.id + '#' + n shaKey = repo.id + ' ' + c.sha sha = c.sha source = source target = target implicit = c.parsed.target == '' state = merged ? 'merged' : 'open' head = head heads = [head] authorId = author authorName = author != null ? nameOfUser(author) : c.author createdMs = quiet ? c.ct : stamp updatedMs = quiet ? c.ct : stamp }
  283. if (setPullRef(slug, n, head)) {
  284. id = pullRecs.put(rec)
  285. if (id != null && !quiet) {
  286. saved = pullRecs.fetch(id)
  287. changes.push(changeOf(saved, merged ? 'merged' : 'opened', null, head, false, merged ? mergeCommitOf(slug, c.sha, targetTip) : null, pusherId))
  288. }
  289. }
  290. }
  291. }
  292. return changes
  293. }
  294. // number the PRs a repo already has, ONCE (quiet); call it before a push is taken and when /pulls is built
  295. static ensurePulls = (slug) => {
  296. repo = repoBySlug(slug)
  297. if (repo == null || isInitialized(repo.id)) { return null }
  298. syncNow(slug, null, true)
  299. // an empty repo (no branch yet) has nothing to number and is initialized too: its first PR is a live one
  300. pullInit.put({ rid = repo.id })
  301. return null
  302. }
  303. // THE ENTRY: compare git with the records. Never fails the caller: whatever goes wrong yields the changes found so far (none).
  304. // userId = the gitoria user who pushed or merged (null when unknown). Every change is logged (logChange) and returned.
  305. static syncPulls = (slug, userId) => {
  306. ensurePulls(slug)
  307. changes = syncNow(slug, userId, false)
  308. for (c of changes) { logChange(slug, c) }
  309. return changes
  310. }
  311. // All writes to pull records stay in this topic file. Callers check mayPush first.
  312. static setManualPull = (String userId, String slug, Number number, Boolean closed) => {
  313. repo = repoBySlug(slug)
  314. ensurePulls(slug)
  315. found = repo == null ? null : recordByNumber(repo.id, number)
  316. if (found == null) { return { error = 'no such pull request' code = 404 } }
  317. claim = claimPull(found.id)
  318. if (claim == null) { return { error = 'this pull request is being updated; try again' code = 409 reason = 'busy' } }
  319. result = writeManualPull(userId, slug, found.id, closed)
  320. releasePull(claim)
  321. return result
  322. }
  323. // Only called while holding this PR's claim; no git calls between the fresh read and replacement.
  324. static writeManualPull = (String userId, String slug, String id, Boolean closed) => {
  325. rec = pullRecs.fetch(id)
  326. if (rec == null) { return { error = 'no such pull request' code = 404 } }
  327. if (rec.state == 'merged') { return { error = 'this pull request is already merged' code = 409 reason = 'already_merged' } }
  328. if ((closed && rec.state != 'open') || (!closed && (rec.state != 'closed' || rec.manualClosedBy == null))) {
  329. return { error = 'this pull request cannot change to that state' code = 409 reason = 'invalid_state' }
  330. }
  331. u = rec
  332. u.state = closed ? 'closed' : 'open'
  333. u.manualClosedBy = closed ? userId : null
  334. u.manualClosedMs = closed ? now() : null
  335. u.updatedMs = now()
  336. pullRecs.update(rec.id, u)
  337. change = changeOf(u, closed ? 'closed' : 'reopened', rec.head, rec.head, false, null, userId)
  338. logChange(slug, change)
  339. return { ok = true change = change }
  340. }
  341. // the change log until gitoria#43 sends events: one JSON line in storage/pull-changes.log (and the console)
  342. static logChange = (slug, c) => {
  343. repo = repoBySlug(slug)
  344. line = JSON.stringify({ time = timestamp(now()) repoId = repo != null ? repo.id : null slug = slug number = c.number action = c.action before = c.before after = c.after forced = c.forced mergeCommit = c.mergeCommit sender = c.sender })
  345. appendFile(changeLog, line + NL, 384)
  346. console.log('pull-change ' + line)
  347. return null
  348. }
  349. // ---- the contract's `pull` object (§4) --------------------------------------------------------------------
  350. static pullObject = (String slug, Number n, Hybrid approvalRows = null) => {
  351. repo = repoBySlug(slug)
  352. if (repo == null || n == null) { return null }
  353. rec = recordByNumber(repo.id, n)
  354. if (rec == null) { return null }
  355. msg = gitRaw(slug, ['log', '-1', '--format=%B', rec.sha])
  356. lines = msg != null && msg.exit == 0 ? msg.lines : []
  357. pr = lines.length > 0 ? parsePull(lines[0]) : null
  358. title = pr != null && pr.title != '' ? pr.title : (rec.source != '' ? rec.source : rec.sha.slice(0, 8))
  359. body = bodyOfLines(lines)
  360. baseTip = firstLine(slug, ['rev-parse', '--verify', '-q', 'refs/heads/' + rec.target])
  361. mergeBase = baseTip != '' ? firstLine(slug, ['merge-base', baseTip, rec.head]) : ''
  362. project = repo.tktProject != null ? repo.tktProject : ''
  363. statuses = []
  364. for (r of statusesOf(repo.id, rec.head)) { statuses.push(statusJson(r)) }
  365. return {
  366. number = rec.number
  367. title = title
  368. body = body
  369. draft = false
  370. state = rec.state
  371. author = { id = rec.authorId name = rec.authorName }
  372. source = rec.source
  373. target = rec.target
  374. head = rec.head
  375. ref = 'refs/pull/' + rec.number + '/head'
  376. baseRef = 'refs/heads/' + rec.target
  377. base = baseTip != '' ? baseTip : null
  378. mergeBase = mergeBase != '' ? mergeBase : null
  379. tickets = ticketNames(title + NL + body, project)
  380. url = repoOrigin(slug) + '/pulls/' + rec.number
  381. created = timestamp(rec.createdMs)
  382. updated = timestamp(rec.updatedMs)
  383. statuses = statuses
  384. required = requiredOf(repo.id)
  385. approvers = approversOf(repo.id)
  386. approvals = approvalsJson(approvalRows == null ? approvalsOf(repo.id, rec.number) : approvalRows, rec.head)
  387. }
  388. }
  389. // the rows of /pulls with their number: `number` (0 = not stored) and `numberText` ("#3")
  390. static withNumbers = (list, slug) => {
  391. out = []
  392. repo = repoBySlug(slug)
  393. for (p of list) {
  394. q = p
  395. rec = repo != null ? recordBySha(repo.id, p.sha) : null
  396. q.number = rec != null ? rec.number : 0
  397. q.numberText = rec != null ? '#' + rec.number : ''
  398. q.pageHref = rec != null ? px(slug) + '/pulls/' + rec.number : p.href
  399. out.push(q)
  400. }
  401. return out
  402. }

Branches

Latest commits

  • e53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mre
  • d8608224close and reopen: keep a manual close against sync (#56)mre
  • ffb60746|||PR close and reopen pull requests (#56)mre
  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre