Skip to content

Commit

Permalink
Revert "Penny ignore reporting "Do Not Merge" PRs in Discord"
Browse files Browse the repository at this point in the history
This reverts commit 538c98e.
  • Loading branch information
MahdiBM committed Jan 20, 2025
1 parent 538c98e commit 0ac8d89
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .sourcekit-lsp/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"backgroundIndexing": true,
"backgroundPreparationMode": "enabled",
"backgroundPreparationMode": "build",
"maxCoresPercentageToUseForBackgroundIndexing": 0.7,
"experimentalFeatures": ["on-type-formatting"]
}
7 changes: 0 additions & 7 deletions Lambdas/GHHooks/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ enum Constants {
static let guildID: GuildSnowflake = "431917998102675485"
static let botDevUserID: UserSnowflake = "290483761559240704"

static let trustedGitHubUserIds: [Int64] = [
69_189_821, // Paul
9_938_337, // Tim
1_130_717, // Gwynne
54_685_446, // Mahdi
]

enum GitHub {
/// The user id of Penny.
static let userID = 139_480_971
Expand Down
9 changes: 2 additions & 7 deletions Lambdas/GHHooks/EventHandler/Handlers/PRCoinGiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ struct PRCoinGiver {
repoFullName: repo.fullName,
branch: branch
)
for pr in prs {
if pr.mergedAt == nil {
logger.debug("PR is not merged yet", metadata: ["pr": "\(pr)"])
continue
}
for pr in try await getPRsRelatedToCommit() {
guard pr.mergedAt != nil else { continue }
let user = try pr.user.requireValue()
var usersToReceiveCoins = codeOwners.contains(user: user) ? [] : [user.id]

Expand Down Expand Up @@ -91,8 +88,6 @@ struct PRCoinGiver {
}

func giveCoin(userId: Int64, pr: SimplePullRequest) async throws {
logger.trace("Giving a coin", metadata: ["userId": .stringConvertible(userId)])

guard
let member = try await context.requester.getDiscordMember(
githubID: "\(userId)"
Expand Down
2 changes: 0 additions & 2 deletions Lambdas/GHHooks/EventHandler/Handlers/PRHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ struct PRHandler {
}

func onEdited() async throws {
if self.pr.isIgnorableDoNotMergePR { return }
try await self.editPRReport()
}

func onOpened() async throws {
if self.pr.isIgnorableDoNotMergePR { return }
try await self.makeReporter().reportCreation()
}

Expand Down
20 changes: 10 additions & 10 deletions Lambdas/GHHooks/EventHandler/Handlers/ReleaseMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ struct ReleaseMaker {
}

func isNewContributor(codeOwners: CodeOwners, existingContributors: Set<Int64>) -> Bool {
pr.authorAssociation != .owner
&& !pr.user.isBot
&& !codeOwners.contains(user: pr.user)
pr.authorAssociation != .owner && !pr.user.isBot && !codeOwners.contains(user: pr.user)
&& !existingContributors.contains(pr.user.id)
}

Expand All @@ -307,9 +305,9 @@ struct ReleaseMaker {
)
)

do {
return try response.ok.body.json
} catch {
guard case let .ok(ok) = response,
case let .json(json) = ok.body
else {
logger.warning(
"Could not find reviews",
metadata: [
Expand All @@ -318,6 +316,8 @@ struct ReleaseMaker {
)
return []
}

return json
}

func getExistingContributorIDs() async throws -> Set<Int64> {
Expand Down Expand Up @@ -357,9 +357,9 @@ struct ReleaseMaker {
)
)

do {
let ok = try response.ok
let json = try ok.body.json
if case let .ok(ok) = response,
case let .json(json) = ok.body
{
/// Example of a `link` header: `<https://api.github.com/repositories/49910095/contributors?page=6>; rel="prev", <https://api.github.com/repositories/49910095/contributors?page=8>; rel="next", <https://api.github.com/repositories/49910095/contributors?page=8>; rel="last", <https://api.github.com/repositories/49910095/contributors?page=1>; rel="first"`
/// If the header contains `rel="next"` then we'll have a next page to fetch.
let hasNext =
Expand All @@ -378,7 +378,7 @@ struct ReleaseMaker {
]
)
return (ids, hasNext)
} catch {
} else {
logger.error(
"Error when fetching contributors but will continue",
metadata: [
Expand Down
39 changes: 39 additions & 0 deletions Lambdas/GHHooks/Extensions/+PR.Label.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import GitHubAPI

extension PullRequest {

enum KnownLabel: String {
case semVerMajor = "semver-major"
case semVerMinor = "semver-minor"
case semVerPatch = "semver-patch"
case semVerNoOp = "semver-noop"
case release = "release"
case noReleaseNeeded = "no-release-needed"
case translationUpdate = "translation-update"
case noTranslationNeeded = "no-translation-needed"

func toBump() -> SemVerBump? {
switch self {
case .semVerMajor: return .major
case .semVerMinor: return .minor
case .semVerPatch: return .patch
case .release: return .releaseStage
case .semVerNoOp, .noReleaseNeeded, .translationUpdate, .noTranslationNeeded: return nil
}
}
}

var knownLabels: [KnownLabel] {
self.labels.compactMap {
KnownLabel(rawValue: $0.name)
}
}
}

extension SimplePullRequest {
var knownLabels: [PullRequest.KnownLabel] {
self.labels.compactMap {
PullRequest.KnownLabel(rawValue: $0.name)
}
}
}
92 changes: 0 additions & 92 deletions Lambdas/GHHooks/Extensions/+PR.swift

This file was deleted.

1 change: 0 additions & 1 deletion Lambdas/GitHubAPI/Aliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package typealias Repository = Components.Schemas.Repository
package typealias User = Components.Schemas.SimpleUser
package typealias PullRequest = Components.Schemas.PullRequest
package typealias SimplePullRequest = Components.Schemas.PullRequestSimple
package typealias AuthorAssociation = Components.Schemas.AuthorAssociation
package typealias Issue = Components.Schemas.Issue
package typealias Label = Components.Schemas.Label
package typealias Release = Components.Schemas.Release
Expand Down

0 comments on commit 0ac8d89

Please sign in to comment.