Skip to content

Commit

Permalink
Merge pull request #1670 from OneSignal/user-model/merge-from-main
Browse files Browse the repository at this point in the history
[User Model] merge from main
  • Loading branch information
brismithers authored and jinliu9508 committed Jan 31, 2024
2 parents cff11ab + 6025317 commit 0c1a655
Show file tree
Hide file tree
Showing 36 changed files with 9,480 additions and 26 deletions.
58 changes: 58 additions & 0 deletions .github/os_probot_metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Based on probot-metadata - https://github.com/probot/metadata
*/
const regex = /\n\n<!-- probot = (.*) -->/

const { Octokit } = require("@octokit/action")

const octokit = new Octokit()

module.exports = (context, issue = null) => {
console.log(context)
const prefix = "onesignal-probot"

if (!issue) issue = context.payload.issue

return {
async get (key = null) {
let body = issue.body

if (!body) {
body = (await octokit.issues.get(issue)).data.body || ''
}

const match = body.match(regex)

if (match) {
const data = JSON.parse(match[1])[prefix]
return key ? data && data[key] : data
}
},

async set (key, value) {
let body = issue.body
let data = {}

if (!body) body = (await octokit.issues.get(issue)).data.body || ''

body = body.replace(regex, (_, json) => {
data = JSON.parse(json)
return ''
})

if (!data[prefix]) data[prefix] = {}

if (typeof key === 'object') {
Object.assign(data[prefix], key)
} else {
data[prefix][key] = value
}

body = `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->`

const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/")
const issue_number = context.payload.issue.number
return octokit.issues.update({ owner, repo, issue_number, body })
}
}
}
25 changes: 25 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name-template: $RESOLVED_VERSION
tag-template: $RESOLVED_VERSION
categories:
- title: 🚀 Features
label: Enhancement / Feature
- title: 🐛 Bug Fixes
label: Bug
- title: 🧰 Improvements
label: Improvement
change-template: '- $TITLE (#$NUMBER)'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Other Changes
$CHANGES
47 changes: 47 additions & 0 deletions .github/set_response_times.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function calcResponseTimeForIssueCreatedAt(createdAt) {
const issueOpenedDate = new Date(createdAt);
const issueTriagedDate = new Date();
const businessDaysResponseTime = calcBusinessDaysBetweenDates(issueOpenedDate, issueTriagedDate);
return businessDaysResponseTime;
}

function calcBusinessDaysBetweenDates(openedDate, triagedDate) {
let differenceInWeeks, responseTime;
if (triagedDate < openedDate)
return -1; // error code if dates transposed
let openedDay = openedDate.getDay(); // day of week
let triagedDay = triagedDate.getDay();
openedDay = (openedDay == 0) ? 7 : openedDay; // change Sunday from 0 to 7
triagedDay = (triagedDay == 0) ? 7 : triagedDay;
openedDay = (openedDay > 5) ? 5 : openedDay; // only count weekdays
triagedDay = (triagedDay > 5) ? 5 : triagedDay;
// calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
differenceInWeeks = Math.floor((triagedDate.getTime() - openedDate.getTime()) / 604800000);
if (openedDay < triagedDay) { //Equal to makes it reduce 5 days
responseTime = (differenceInWeeks * 5) + (triagedDay - openedDay);
}
else if (openedDay == triagedDay) {
responseTime = differenceInWeeks * 5;
}
else {
responseTime = ((differenceInWeeks + 1) * 5) - (openedDay - triagedDay);
}
return (responseTime);
}

module.exports = async(context, osmetadata) => {
const foundResponseTime = await osmetadata(context).get('response_time_in_business_days');
if (foundResponseTime) {
const foundString = "already found response time in business days: " + foundResponseTime
console.log(foundString);
return foundString;
}
if (context.payload.comment && context.payload.comment.author_association != "MEMBER" && context.payload.comment.author_association != "OWNER" && context.payload.comment.author_association != "CONTRIBUTOR") {
return;
}
const businessDaysResponseTime = calcResponseTimeForIssueCreatedAt(context.payload.issue.created_at);
console.log("response time in business days: " + businessDaysResponseTime);
const result = osmetadata(context, context.payload.issue).set('response_time_in_business_days', businessDaysResponseTime)
console.log("osmetadata update result: " + result);
return "set response time in business days: " + businessDaysResponseTime;
}
34 changes: 34 additions & 0 deletions .github/workflows/Zapier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This is an action to close asana tasks that were generated by Github issues

name: Zapier web hook

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
issues:
types: [closed]

permissions:
issues: read

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs a set of commands using the runners shell
- name: Call Zapier web hook to close Asana task
if: ${{ !github.event.issue.pull_request }}
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw '{
"task_name" : "$ISSUE_TITLE"
}'
41 changes: 41 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- main
# pull_request event is required only for autolabeler
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]

permissions:
contents: read

jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
# (Optional) GitHub Enterprise requires GHE_HOST variable set
#- name: Set GHE_HOST
# run: |
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV

# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# with:
# config-name: my-config.yml
# disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/set_response_time.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Set Response Time
on:
issue_comment:
types:
- created
issues:
types:
- closed
jobs:
calculate:
name: set reponse time for the issue
if: github.event.issue.pull_request == null
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- run: npm install @octokit/[email protected]
- uses: actions/github-script@v6
id: set-time
with:
result-encoding: string
script: |
const os_probot_metadata = require('./.github/os_probot_metadata.js')
const set_response_time = require('./.github/set_response_times.js')
return await set_response_time(context, os_probot_metadata)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get result
run: echo "${{steps.set-time.outputs.result}}" >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion Examples/OneSignalDemo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
Expand Down
1 change: 0 additions & 1 deletion Examples/OneSignalDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.14.0, 0.99.99]'
classpath 'com.huawei.agconnect:agcp:1.6.2.300'

// TODO: Do not place your application dependencies here; they belong
Expand Down
16 changes: 1 addition & 15 deletions OneSignalSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ buildscript {
huaweiAgconnectVersion = '1.6.2.300'
huaweiHMSPushVersion = '6.3.0.304'
huaweiHMSLocationVersion = '4.0.0.300'
kotlinVersion = '1.6.21'
kotestVersion = '5.5.0'
kotlinVersion = '1.5.32'
ktlintVersion = '11.0.0'
detektVersion = '1.21.0'
onesignalGradlePluginVersion = '[0.14.0, 0.99.99]'
}

repositories {
google()
mavenCentral()

// OneSignal-Gradle-Plugin - Local testing
// maven { url uri('../../repo') }

// OneSignal-Gradle-Plugin - Public version
gradlePluginPortal()

// Huawei maven
maven { url 'https://developer.huawei.com/repo/' }
}
Expand All @@ -40,12 +32,6 @@ buildscript {

classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlintVersion"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion"

// OneSignal-Gradle-Plugin - Local testing
// classpath 'com.onesignal:onesignal-gradle-plugin:[0.8.1, 0.99.99]'

// OneSignal-Gradle-Plugin - Public version
classpath "gradle.plugin.com.onesignal:onesignal-gradle-plugin:$onesignalGradlePluginVersion"
}
}

Expand Down
5 changes: 3 additions & 2 deletions OneSignalSDK/onesignal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ dependencies {

// firebase-messaging:18.0.0 is the last version before going to AndroidX
// firebase-messaging:19.0.0 is the first version using AndroidX
// firebase-messaging:23.0.0 incoporates fix for SecurityException: Not allowed to bind to service
api('com.google.firebase:firebase-messaging') {
version {
require '[19.0.0, 22.0.99]'
prefer '22.0.0'
require '[19.0.0, 23.0.99]'
prefer '23.0.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion OneSignalSDK/onesignal/maven-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Global {
static def POM_NAME = 'OneSignal'
static def POM_ARTIFACT_ID = 'OneSignal'
static def POM_PACKAGING = 'aar'
static def VERSION_NAME = '4.8.2'
static def VERSION_NAME = '4.8.7'

static def GROUP_ID = 'com.onesignal'
static def POM_DESCRIPTION = 'OneSignal Android SDK'
Expand Down
Loading

0 comments on commit 0c1a655

Please sign in to comment.