Skip to content

Commit

Permalink
Handle poll interval and API token better
Browse files Browse the repository at this point in the history
- Token expires every hour, so a new token needs to be fetched every
  time, rather than just being able to get one at object
  initialization.

- The "stalledDiscussionPollTimeMins" property set in the
  bf2-arch-bot.yml seemingly can't be used in the @scheduled
  annotation, since it's not available early enough.
  • Loading branch information
grdryn committed Apr 19, 2023
1 parent 322104a commit cc25213
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bot.enable.pr-review=false
bot.enable.state-machine=false
bot.enable.create-draft=true

BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s

## Stuff required by the github app framework

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public class StalledDiscussionFlow {
ArchBotConfig config;

@Inject
void init(GitHubService service, GitHubConfigFileProvider configFileProvider) throws IOException {
GitHubService service;

@Inject
void init(GitHubConfigFileProvider configFileProvider) throws IOException {
if (!enabled) {
LOG.debug("Ignoring init: disabled due to {}=false", ENABLE);
} else if (installationId != null) {
Expand All @@ -75,8 +78,6 @@ void init(GitHubService service, GitHubConfigFileProvider configFileProvider) th
}
}



/**
* When
* every N hours
Expand All @@ -97,7 +98,7 @@ void init(GitHubService service, GitHubConfigFileProvider configFileProvider) th
* If the PR has been opened for > Y hours then "stalled-discussion"
*/
// TODO similar method as this, but for OVERDUE
@Scheduled(every="60s")
@Scheduled(every = "{BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION}")
public void checkForStalledDiscussions() throws IOException {
if (!enabled) {
LOG.debug("Ignoring scheduled trigger: disabled due to {}=false", ENABLE);
Expand All @@ -106,7 +107,9 @@ public void checkForStalledDiscussions() throws IOException {
long now = System.currentTimeMillis();
long thresh = now - 24*40*60*1000L;
LOG.info("Checking for stalled discussions");
// TODO need a parameter for this installation id

LOG.debug("Updating installation client to get new token (expires every 1h)");
client = service.getInstallationClient(installationId);

var results = client.searchIssues()
.isOpen()
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
quarkus.log.level=DEBUG
quarkus.log.level=DEBUG
bot.enable.stalled-discussion=true
bot.enable.create-draft=true
BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s
3 changes: 2 additions & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ FqD6xNtjmuaS5enErcCAMbZtzA7TNzvGaVO+xB/GfQ2QHS8/mrTesvQsTUZwC+ji\
E0/FAoGATJvuAfgy9uiKR7za7MigYVacE0u4aD1sF7v6D4AFqBOGquPQQhePSdz9\
G/UUwySoo+AQ+rd2EPhyexjqXBhRGe+EDGFVFivaQzTT8/5bt/VddbTcw2IpmXYj\
LW6V8BbcP5MRhd2JQSRh16nWwSQJ2BdpUZFwayEEQ6UcrMfqvA0=\
-----END RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s

0 comments on commit cc25213

Please sign in to comment.