Skip to content

Commit

Permalink
devict#55 - added customizable number of pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cjprieb committed Oct 8, 2022
1 parent 23cffb4 commit 4596c55
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ type Project struct {
Visible bool
}

type HacktoberfestConfiguration struct {
RequiredPullRequestCount int
RequiredPullRequestCountEng string
TimesToRepeat string
}

var hacktoberfestOptions = HacktoberfestConfiguration{
RequiredPullRequestCount: 2, // the number of pull requests required to qualify for this year.
RequiredPullRequestCountEng: "two pull requests", // the required number written out fully
TimesToRepeat: "Repeat 1 more times.", // the value in this sentence should be one less than the required count.
}

// These specific projects also count
var projects = map[string]Project{
"imacrayon/eventsinwichita": {
Expand Down Expand Up @@ -172,10 +184,12 @@ func home(w http.ResponseWriter, r *http.Request) {
Orgs map[string]bool
Projects map[string]Project
Year int
Config HacktoberfestConfiguration
}{
Orgs: orgs,
Projects: projects,
Year: time.Now().Year(),
Config: hacktoberfestOptions,
}
v.HTML(w, http.StatusOK, "home", data)
}
Expand Down
4 changes: 3 additions & 1 deletion profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ func profile(w http.ResponseWriter, r *http.Request) {
Projects map[string]Project
User goth.User
New bool
Config HacktoberfestConfiguration
Year int
}{
Orgs: orgs,
Projects: projects,
User: u,
New: n,
Year: time.Now().Year(),
Config: hacktoberfestOptions,
Year: time.Now().Year(),
}

v.HTML(w, http.StatusOK, "profile", info)
Expand Down
13 changes: 9 additions & 4 deletions public/js/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function checkPRs() {

$.ajax({type: 'GET', url: '/api/prs'})
.then(function(data) {
var requiredPullRequestsCount = $('#required-pull-requests-count').val();
console.log("requiredPullRequestsCount: ", requiredPullRequestsCount);
var validCount = 0;
results.empty()
data.forEach(function(p, i) {
Expand All @@ -79,12 +81,15 @@ function checkPRs() {
message = 'You have not opened any Pull Requests on public GitHub projects during October 2019.';
} else if (validCount === 0) {
// Some PRs but none counts
message = 'You have ' + data.length + ' Pull Request(s) but none of them are against approved repos.';
} else if (validCount < 2) {
var pullRequestsString = data.length == 1 ? 'Pull Request' : 'Pull Requests'
message = 'You have ' + data.length + ' ' + pullRequestsString + ' but none of them are against approved repos.';
} else if (validCount < requiredPullRequestsCount) {
// Some PRs that count but not quite 2
message = 'Nice! You have ' + validCount + ' Pull Request(s) that count for devICT Hacktoberfest. Keep it up!';
var pullRequestsString = validCount == 1 ? 'Pull Request' : 'Pull Requests'
var countsString = validCount == 1 ? 'counts' : 'count' // grammar agreement with singular or plural subject
message = 'Nice! You have <b>' + validCount + ' ' + pullRequestsString + '</b> that ' + countsString + ' for devICT Hacktoberfest. Keep it up!';
} else {
// >= 2 valid PRs! Woohoo!
// >= 'requiredPullRequestsCount' valid PRs! Woohoo!
message = 'Excellent! You have hit the goal! Maybe hop in the devICT Slack and help others hit their goal too!';
}

Expand Down
6 changes: 3 additions & 3 deletions templates/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
-->
<div class="prose prose-xl text-gray-500">
<p class="text">This is a blatant attempt to piggyback off the popularity of the global <a class="dark" href="https://hacktoberfest.digitalocean.com">Hacktoberfest event</a> from Digital Ocean and GitHub. Submit two pull requests to qualifying Wichita projects during the month of October and receive stickers from us!</p>
<p class="text">This is a blatant attempt to piggyback off the popularity of the global <a class="dark" href="https://hacktoberfest.digitalocean.com">Hacktoberfest event</a> from Digital Ocean and GitHub. Submit {{ .Config.RequiredPullRequestCountEng }} to qualifying Wichita projects during the month of October and receive stickers from us!</p>
</div>
<div class="mb-1 sm:flex sm:justify-center md:justify-start">
<div class="rounded-md shadow">
Expand Down Expand Up @@ -110,7 +110,7 @@
<div class="mt-5">
<h3 class="text-lg leading-6 font-medium text-gray-900">Submit a PR</h3>
<p class="mt-2 text-base leading-6 text-gray-500">
Submit a pull request with your proposed change. Repeat 1 more time.
Submit a pull request with your proposed change. {{ .Config.TimesToRepeat }}
</p>
</div>
</li>
Expand All @@ -122,7 +122,7 @@
<div class="mt-5">
<h3 class="text-lg leading-6 font-medium text-gray-900">Enjoy Your Stickers!</h3>
<p class="mt-2 text-base leading-6 text-gray-500">
After two pull requests, you are eligible to receive a fun set of stickers!
After {{ .Config.RequiredPullRequestCountEng }}, you are eligible to receive a fun set of stickers!
</p>
</div>
</li>
Expand Down
7 changes: 4 additions & 3 deletions templates/layout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<meta name="description" content="Submit two pull requests to qualifying Wichita projects during the month of October and receive cool stickers!">
<meta name="description" content="Submit {{ .Config.RequiredPullRequestCountEng }} to qualifying Wichita projects during the month of October and receive cool stickers!">
<meta name="keywords" content="devICT, Wichita, Hacktoberfest">

<meta property="og:type" content="website"/>
<meta property="og:title" content="Wichita Hacktoberfest {{ .Year }}!"/>
<meta property="og:url" content="https://devict-hacktoberfest.herokuapp.com/"/>
<meta property="og:description" content="Submit two pull requests to qualifying Wichita projects during the month of October and receive cool stickers!"/>
<meta property="og:description" content="Submit {{ .Config.RequiredPullRequestCountEng }} to qualifying Wichita projects during the month of October and receive cool stickers!"/>
<meta property="og:image" content="https://devict-hacktoberfest.herokuapp.com/public/images/social.png"/>

<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@dev_ict">
<meta name="twitter:title" content="devICT Hacktoberfest {{ .Year }}!">
<meta name="twitter:description" content="Submit two pull requests to qualifying Wichita projects during the month of October and receive cool stickers!">
<meta name="twitter:description" content="Submit {{ .Config.RequiredPullRequestCountEng }} to qualifying Wichita projects during the month of October and receive cool stickers!">
<meta name="twitter:image" content="https://devict-hacktoberfest.herokuapp.com/public/images/social.png">

<link rel="apple-touch-icon" sizes="180x180" href="/public/images/icons/apple-touch-icon.png">
Expand All @@ -39,6 +39,7 @@
{{ partial "css" }}
</head>
<body id="#">
<input hidden id="required-pull-requests-count" value='{{ .Config.RequiredPullRequestCount }}' />
{{ yield }}

<!-- Core JavaScript. jQuery, Bootstrap, and Popper -->
Expand Down
2 changes: 1 addition & 1 deletion templates/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</li>
<li class="flex-1 min-w-0">
<strong>Submit a PR</strong><br>
Open a Pull Request back to the original project. This asks the project's maintainer to consider merging your changes into the project. Go pick another issue and start the cycle again. <em>Remember the target is 2 PRs</em>.
Open a Pull Request back to the original project. This asks the project's maintainer to consider merging your changes into the project. Go pick another issue and start the cycle again. <em>Remember the target is {{ .Config.RequiredPullRequestCountEng }}</em>.
</li>
<li class="flex-1 min-w-0">
<strong>Enjoy Your Stickers!</strong><br>
Expand Down

0 comments on commit 4596c55

Please sign in to comment.