From 8d90b0fc33c4399b33cd3db0c6664f5cf8b6fd3e Mon Sep 17 00:00:00 2001 From: Gareth Healy Date: Fri, 5 Jan 2024 14:02:08 +0000 Subject: [PATCH] 1 --- .github/workflows/build.yaml | 8 ++++++ .../commands/CreateWhoAreYouIssueCommand.java | 14 +++++++--- .../client/CreateWhoAreYouIssueService.java | 26 +++++++++++-------- tests/members.csv | 2 ++ 4 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 tests/members.csv diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 10dc073..e425d16 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -90,11 +90,19 @@ jobs: with: name: target + - name: Make github-stats-*-runner executable + run: chmod +x github-stats-*-runner + - name: Run collect-stats for myself env: GITHUB_LOGIN: ${{ secrets.GITHUB_TOKEN }} run: ./github-stats-*-runner collect-stats --organization=garethahealy + - name: Run collect-stats for myself + env: + GITHUB_LOGIN: ${{ secrets.GITHUB_TOKEN }} + run: echo "todo" #./github-stats-*-runner create-who-are-you-issues --dry-run=true --organization=garethahealy --issue-repo=github-stats --members-csv=tests/members.csv --fail-if-no-vpn=false + - name: Upload github-output.csv uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4 with: diff --git a/src/main/java/com/garethahealy/githubstats/commands/CreateWhoAreYouIssueCommand.java b/src/main/java/com/garethahealy/githubstats/commands/CreateWhoAreYouIssueCommand.java index 3216991..f86623d 100644 --- a/src/main/java/com/garethahealy/githubstats/commands/CreateWhoAreYouIssueCommand.java +++ b/src/main/java/com/garethahealy/githubstats/commands/CreateWhoAreYouIssueCommand.java @@ -15,11 +15,17 @@ public class CreateWhoAreYouIssueCommand implements Runnable { @CommandLine.Option(names = {"-org", "--organization"}, description = "GitHub organization", required = true) String organization; - @CommandLine.Option(names = {"-repo", "--org-repo"}, description = "Repo name for 'org'", required = true) + @CommandLine.Option(names = {"-repo", "--issue-repo"}, description = "Repo where the issues should be created, i.e.: 'org'", required = true) String orgRepo; - @CommandLine.Option(names = {"-dry", "--dry-run"}, description = "Dry-run aka dont actually create the GitHub issues", required = true) - Boolean dryRun; + @CommandLine.Option(names = {"-dry", "--dry-run"}, description = "Dry-run aka don't actually create the GitHub issues", required = true) + boolean dryRun; + + @CommandLine.Option(names = {"-i", "--members-csv"}, description = "CSV container current known members", required = true) + String membersCsv; + + @CommandLine.Option(names = {"-vpn", "--fail-if-no-vpn"}, description = "Throw an exception if can't connect to LDAP", required = true) + boolean failNoVpn; @Inject CreateWhoAreYouIssueService createWhoAreYouIssueService; @@ -29,7 +35,7 @@ public void run() { try { //TODO: for time being, always dry-run dryRun = true; - createWhoAreYouIssueService.run(organization, orgRepo, dryRun); + createWhoAreYouIssueService.run(organization, orgRepo, dryRun, membersCsv, failNoVpn); } catch (IOException | LdapException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/garethahealy/githubstats/rest/client/CreateWhoAreYouIssueService.java b/src/main/java/com/garethahealy/githubstats/rest/client/CreateWhoAreYouIssueService.java index 75faa89..db17c41 100644 --- a/src/main/java/com/garethahealy/githubstats/rest/client/CreateWhoAreYouIssueService.java +++ b/src/main/java/com/garethahealy/githubstats/rest/client/CreateWhoAreYouIssueService.java @@ -29,14 +29,14 @@ public class CreateWhoAreYouIssueService extends BaseGitHubService { @Inject Logger logger; - public void run(String organization, String orgRepoName, boolean isDryRun) throws IOException, LdapException { + public void run(String organization, String issueRepo, boolean isDryRun, String membersCsv, boolean failNoVpn) throws IOException, LdapException { GitHub gitHub = getGitHub(); GHOrganization org = gitHub.getOrganization(organization); - GHRepository orgRepo = org.getRepository(orgRepoName); + GHRepository orgRepo = org.getRepository(issueRepo); List members = org.listMembers().toList(); - Set usernamesToIgnore = getUsernamesToIgnore(); + Set usernamesToIgnore = getUsernamesToIgnore(membersCsv); logger.infof("There are %s members", members.size()); logger.infof("There are %s members we already have emails for who will be ignored", usernamesToIgnore.size()); @@ -55,7 +55,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw "https://red.ht/github-redhat-cop-username"); if (isDryRun) { - logger.infof("DRY-RUN: Would have created issue for %s", current.getLogin()); + logger.infof("DRY-RUN: Would have created issue for %s in %s", current.getLogin(), orgRepo.getName()); } else { builder.create(); @@ -69,7 +69,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw Set membersLogins = getMembersLogins(members); for (String current : usernamesToIgnore) { if (!membersLogins.contains(current)) { - logger.infof("Have a google form response but they are not part the git hub org anymore for %s", current); + logger.infof("Have a google form response but they are not part the github org anymore for %s", current); } } @@ -78,7 +78,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw //ldapsearch -x -h ldap.corp.redhat.com -b dc=redhat,dc=com -s sub 'uid=gahealy' Dn systemDn = new Dn("dc=redhat,dc=com"); try (LdapConnection connection = new LdapNetworkConnection("ldap.corp.redhat.com")) { - for (String current : getCollectedEmails()) { + for (String current : getCollectedEmails(membersCsv)) { String uid = current.split("@")[0]; try (EntryCursor cursor = connection.search(systemDn, "(uid=" + uid + ")", SearchScope.SUBTREE)) { boolean found = false; @@ -93,16 +93,20 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw } } } catch (InvalidConnectionException ex) { - logger.error("Unable to search ldap for users. Are you on the VPN?", ex); + if (failNoVpn) { + logger.error("Unable to search ldap for users. Are you on the VPN?", ex); + } else { + logger.warn("Unable to search ldap for users. Are you on the VPN?", ex); + } } logger.info("Ldap Lookup DONE"); } - private Set getUsernamesToIgnore() throws IOException { + private Set getUsernamesToIgnore(String membersCsv) throws IOException { Set answer = new HashSet<>(); CSVFormat csvFormat = CSVFormat.Builder.create(CSVFormat.DEFAULT).setSkipHeaderRecord(true).build(); - try (Reader in = new FileReader("GitHub Red Hat CoP Members (Responses) - Form Responses 1.csv")) { + try (Reader in = new FileReader(membersCsv)) { Iterable records = csvFormat.parse(in); for (CSVRecord record : records) { answer.add(record.get("What is your GitHub username?")); @@ -112,10 +116,10 @@ private Set getUsernamesToIgnore() throws IOException { return answer; } - private List getCollectedEmails() throws IOException { + private List getCollectedEmails(String membersCsv) throws IOException { List answer = new ArrayList<>(); CSVFormat csvFormat = CSVFormat.Builder.create(CSVFormat.DEFAULT).setSkipHeaderRecord(true).build(); - try (Reader in = new FileReader("GitHub Red Hat CoP Members (Responses) - Form Responses 1.csv")) { + try (Reader in = new FileReader(membersCsv)) { Iterable records = csvFormat.parse(in); for (CSVRecord record : records) { answer.add(record.get("Email Address")); diff --git a/tests/members.csv b/tests/members.csv new file mode 100644 index 0000000..0e9ff16 --- /dev/null +++ b/tests/members.csv @@ -0,0 +1,2 @@ +Timestamp,Email Address,What is your GitHub username? +1/26/2022 15:37:03,gahealy@redhat.com,garethahealy \ No newline at end of file